두 개의 ICollection
중 하나를 갖고 싶습니다. 현재 foreach 루프를 사용하여이 작업을 수행하고 있지만 장황하고 끔찍한 느낌입니다. Java의 addAll()
에 해당하는 C#은 무엇입니까? 이 문제의C# : 두 ICollections의 연합? (Java의 addAll()과 동등)
예 :
ICollection<IDictionary<string, string>> result = new HashSet<IDictionary<string, string>>();
// ...
ICollection<IDictionary<string, string>> fromSubTree = GetAllTypeWithin(elementName, element);
foreach(IDictionary<string, string> dict in fromSubTree) { // hacky
result.Add(dict);
}
// result is now the union of the two sets
ToList()에 좋은 호출 –
불행히도, 노동 조합은 원점과 운명이 세트 였고 반복되는 요소를 간과하는 것처럼 작동합니다. 따라서이 작업은 Java 및 Collection과 동일한 것은 아닙니다. Collection.addAll() 구현은 반복되는 요소가 유효한 목록 일 수 있습니다. –
@edalorzo이 경우 Enumerable.Concat 대신 http://msdn.microsoft.com/en-us/library/bb302894를 사용할 수 있습니다. –