Coding/C#

C# 특정 오브젝트의 내부 List값 복사하기 object as List<>

Miuna3 2016. 12. 6. 22:18




만약 클래스중에 List<Name> , List<Phone> , List<Home>을 가지고 있는 클래스를 사용한 오브젝트가 있다고 가정하자.

그럼 그 오브젝트 안에는 앞서 말했던 List들이 존재하고 있다.


그 오브젝트내용을 새로운 오브젝트 temp로 복사한 후, 아래와 같이 따로 분류해 낼 수 있다.



List<Name> name = null;
List<Phone> phone = null;
List<Home> home = null;

object temp = GetObject();

home = temp as List<Home>;
phone = temp as List<Phone>;
name =
temp as List<Home>;