내 방법으로 첫 번째 예 http://www.dotnetperls.com/convert-list-string을 구현하기 위해 노력하고있어하지만 난 방법을하기위한 곳 중 2 번째 인수와 일치하는 힘든 시간을 보내고 있습니다 string.Join하려고 :IList의
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 ("사용 ", 테스트);" 대신 목록에 무엇이 어떤 이유로
"Ilistprac.Location, Ilistprac.Location, Ilistprac.Location"
: 내가 어떤 이유로, 체크 표시 내 출력, 출력이 닫기 전에, 작동합니다.
아아 네, 4.0 버전을 사용하고 있습니다. – nhat
나는이 유익에 응답하기 바로 전에. 내 출력은 다음과 같이 출력됩니다. "Ilistprac.Location, Ilistprac.Location, Ilistprac.Location"및 어떤 이유로 목록의 목록 항목이 아닙니다. – nhat
'Location' 객체에'ToString()'을 오버라이드하지 않았으므로 기본 동작을 얻고 있습니다. – dlev