2012-04-15 8 views
2

私は基本クラスBaseとそれを継承するクラスA/Bを持っています。私は、コードをコンパイルすると、私はこのエラーを得たC言語でOfTypeを持つ型のオブジェクトをフィルタリングする#

public static void RunSnippet() 
{ 
    Base xbase; A a; B b; 
    IEnumerable<Base> list = new List<Base>() {xbase, a, b}; 
    Base f = list.OfType<A>; // I need to get only the object A 
    Console.WriteLine(f); 
} 

error CS0428: Cannot convert method group 'OfType' to non-delegate type 'Base'. Did you intend to invoke the method?

間違って何

public class Base 
{ 
    int x; 
} 
public class A : Base 
{ 
    int y; 
} 
public class B : Base 
{ 
    int z; 
} 

は、私は次のように私は必要なオブジェクトのみをフィルタリングするためにOfTypeを使用しようとしましたコードは?

答えて

関連する問題