Categories: Genel, Programlama, SSS (FAQ), Tip Posted by okutbay on 02.09.2009 16:58 | Yorumlar (0)

For example you have a base class and a class that inherits it like below.

 

    1 public class A

    2 { }

    3 

    4 public class B : A

    5 { }

And you have generic list of these types. Then if you want to convert List<B> to List<A>

You can use this code block:

 

    1 List<B> listB = new List<B>();

    2 List<A> listA = listB.Cast<A>().ToList();

 Happy coding.

 

 

 

Bu yazıyı ilk değerlendiren siz olun

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Yorumlar

Yorum ekle


(Gravatar simgesini gösterecek)  

  Country flag

biuquote
  • Yorum
  • Canlı önizleme
Loading