2010-05-05 30 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 = ...获取列表就像一个组合框.. !谢谢...