2008-09-18 55 views

回答

6

arrayOfAIFoo[]

您的程序一定有其他问题。

你似乎已经嘲笑了一些代码来说明问题,但实际上你的代码(见下文)的作品如您所愿。尝试用真实代码更新此问题 - 或者尽可能接近真实 - 然后我们可以再看一次。

using System; 
public class oink { 
    public static void Main() { 
     A[] aOa = new A[10]; 

     if (aOa is IFoo[]) { Console.WriteLine("aOa is IFoo[]"); } 

    } 
    public interface IFoo {} 
    public class A : IFoo {} 
} 

PS D:\> csc test.cs 
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.1 
for Microsoft (R) .NET Framework version 3.5 
Copyright (C) Microsoft Corporation. All rights reserved. 

PS D:\> D:\test.exe 
aOa is IFoo[] 
PS D:\> 
-3

你可以尝试

if (arrayofA[0] is IFoo) {.....} 

哪种类型的回答你的问题。 arrayOfA是一个数组。数组是一个对象,它实现了ICloneable,IList,ICollection,& IEnumerable。其中不包括IFoo