2010-08-16 53 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