나는 DateTime
이라는 컬렉션이 reportLogs
입니다. 이 Collection<DateTime>
에서 ShortDateString
의 Collection<T>
을 생성해야합니다. 가장 효율적인 방법은 무엇입니까?컬렉션을 다른 컬렉션 (목록 아님)으로 변환
Collection<DateTime> reportLogs = reportBL.GetReportLogs(1, null, null);
Collection<string> logDates = new Collection<string>();
foreach (DateTime log in reportLogs)
{
string sentDate = log.ToShortDateString();
logDates.Add(sentDate);
}
편집는 :
질문에 대한 Collection of string
이다; List of string
아닙니다. 어떻게 문자열 컬렉션을 처리 할 수 있습니까?
참조 :
- Using LINQ to convert List<U> to List<T>
- LINQ convert DateTime to string
- Convert a datetime in a subcollection of collection and use it in LINQ to SQL
- convert Collection<MyType> to Collection<Object> 그냥
IEnumerable<string>
행복 경우
로 변환 // ShortDateString
에를 변환; '문자열 목록'에 관한 것이 아닙니다. '문자열 모음'을 어떻게 처리 할 수 있습니까? – Lijo
@Lijo - ['List '는'ICollection'을 상속합니다. (http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx) - 이것은'List '** IS ** a Collection을 의미합니다. ! –
Jamiec
@Lijo - 또한'Collection'에는'IList '을 사용하는 생성자가 있습니다. 그래서 위의 결과에 대한 목록을 항상 새 Collection으로 전달할 수 있습니다. 이것으로 답변을 업데이트하겠습니다. –
Jamiec