2010-05-05 52 views
1

你好,我怎麼能有一個像目錄在.NET VB的屬性..我的意思是,如果我有我如何限制更多鈔票選項被分配到.NET財產

Property funcion(ByVal _funcion As Int16) As Int16 
    Get 
     Return _funcion 
    End Get 

    Set(ByVal value As Int16) 
     _funcion = value 
    End Set 
End Property 

我想能夠爲此屬性分配有限數量的選項。

例..

Dim a as trick 
a.funcion = (and get a list of possible attributes) ... 

謝謝!

回答

0
Set(ByVal value As Int16) 
    If value < 0 
     Throw New ArgumentException("value must be greater than or equal to 0") 
    _funcion = value 
End Set 

還有compile-time checking這在VS 2010中(儘管它需要VS 2010專業版或更高版本)。

用法示例:

''VB.Net 10/Visual Studio 2010 Professional only 
Set(ByVal value As Int16) 
    Contract.Requires(value >= 0) 
    _funcion = value 
End Set 
0

這裏是如何結束......

Enum _funciont As Short 
      Full = 1 
      Table = 2 
      Login = 3 
End Enum 

Property funcion() As _funciont 

      Get 
       Return CType(_funcion, _funciont) 
      End Get 

      Set(ByVal value As _funciont) 
       _funcion = value 
      End Set 
     End Property 

然後當我把一個s.funcion = ...獲取列表就像一個組合框.. !謝謝...