2010-08-16 62 views
0

这是一个非常基本的问题。get set property as a bool [] return

void Output(int output); - >此使得一个单一输出

bool[] Outputs { get; set; } - >这使得多个输出。我需要实施这个。这是一个声明为接口的API。

在我的课程中,我需要使用它。

我研究了这个http://msdn.microsoft.com/en-us/library/87d83y5b%28VS.80%29.aspx ...但没有我得到和设置返回一个布尔数组的引用。

在上述连杆中,类是:

接口IPOINT { //属性签名: INT X { GET; 集; } int y { get; 集; }}

class Point : IPoint 
{ 
    // Fields: 
    private int _x; 
    private int _y; 

    // Constructor: 
    public Point(int x, int y) 
    { 
     _x = x; 
     _y = y; 
    } 

    // Property implementation: 
    public int x 
    { 
     get 
     { 
     return _x; 
     }  
     set 
     { 
     _x = value; 
     } 
    } 

    public int y 
    { 
     get 
     { 
     return _y; 
     } 
     set 
     { 
     _y = value; 
     } 
    } 
} 

这将是在我的案件类的声明?

回答

1

与MSDN上的示例相同,但将“int”替换为“bool[]”。

1

这里是一个示例实现:

public class YourAPIImpl: IYourAPI 
{ 
    public bool[] Outputs { get; set; } 

    public void Output(int output) 
    { 
     throw new NotImplementedException(); 
    } 
} 
2
public bool[] Outputs {get; set;} 

将创建一个名为 “输出” 返回布尔数组属性。这是一个快捷的语法,如果你想使用更长的语法,那么它会去一些像

private bool[] _outputs; 
public bool[] Outputs 
{ 
    get 
    { 
     return _outputs; 
    } 
    set 
    { 
     _outputs = value; 
    } 
} 
+0

感谢您的答复Vinay。 public interface myInterface bool [] Outputs {get;组; } void Output(int output); } class myClass:Form - >这里我需要使用myInterface。 但myClass继承了Form。那么这里会是什么情况? ? – SLp 2010-08-16 10:41:16

+0

您可以从一个类和多个接口继承。所以只需在表单之后添加命令和接口名称即可。 (myClass:Form,IMyInterface) – VinayC 2010-08-16 11:18:03