最初の例http://www.dotnetperls.com/convert-list-stringをメソッドに実装しようとしていますが、メソッドの2番目の引数を一致させるのに苦労しています。
string printitout = string.Join(",", test.ToArray<Location>);
エラーメッセージ:
The best overloaded method match for 'string.Join(string,
System.Collections.Generic.IEnumerable<string>)' has some invalid arguments
すべてのIListインターフェースもIEnurmerableで実装されています(誰かが私に望まない限り、ここにはリストされていません)。
class IList2
{
static void Main(string[] args)
{
string sSite = "test";
string sSite1 = "test";
string sSite2 = "test";
Locations test = new Locations();
Location loc = new Location();
test.Add(sSite)
test.Add(sSite1)
test.Add(sSite2)
string printitout = string.Join(",", test.ToArray<Location>); //having issues calling what it needs.
}
}
string printitout = string.Join(",", test.ToArray<Location>);
public class Location
{
public Location()
{
}
private string _site = string.Empty;
public string Site
{
get { return _site; }
set { _site = value; }
}
}
public class Locations : IList<Location>
{
List<Location> _locs = new List<Location>();
public Locations() { }
public void Add(string sSite)
{
Location loc = new Location();
loc.Site = sSite;
_locs.Add(loc);
}
}
編集:「string.Join( "、"、test);」を使用してOK チェックマークを付けてこれを閉じる前に、何らかの理由で出力が機能します。
"Ilistprac.Location、Ilistprac.Location、Ilistprac.Location"
リストにあるものの代わりに何らかの理由で。