첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

▶ ReadOnlyCollection<T> 클래스 : 읽기 전용 컬렉션 구하기 예제

using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;

List<int> sourceList = new List<int>();

sourceList.Add(11);
sourceList.Add(12);
 
ReadOnlyCollection<int> targetList = GetReadOnlyCollection<int>(sourceList);

foreach(int value in targetList)
{
    Console.WriteLine(value);
}

 

728x90

 

▶ ReadOnlyCollection<T> 클래스 : 읽기 전용 컬렉션 구하기

using System.Collections.Generic;
using System.Collections.ObjectModel;

#region 읽기 전용 컬렉션 구하기 - GetReadOnlyCollection<TElement>(sourceList)

/// <summary>
/// 읽기 전용 컬렉션 구하기
/// </summary>
/// <typeparam name="TElement">요소 타입</typeparam>
/// <param name="sourceList">소스 리스트</param>
/// <returns>읽기 전용 컬렉션</returns>
public static ReadOnlyCollection<TElement> GetReadOnlyCollection<TElement>(List<TElement> sourceList)
{
    return sourceList.AsReadOnly();
}

#endregion
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요