日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
VB.NET默認(rèn)屬性適用規(guī)則介紹

VB.NET編程語言的出現(xiàn),幫助開發(fā)人員輕松的實(shí)現(xiàn)了許多功能,我們可以利用它來幫助我們提高編程效率。在VB.NET中,接受參數(shù)的屬性可聲明為類的VB.NET默認(rèn)屬性?!澳J(rèn)屬性”是當(dāng)未給對(duì)象命名特定屬性時(shí) Microsoft Visual Basic .NET 將使用的屬性。因?yàn)槟J(rèn)屬性使您得以通過省略常用屬性名使源代碼更為精簡(jiǎn),所以默認(rèn)屬性非常有用。#t#

最適宜作為默認(rèn)屬性的是那些接受參數(shù)并且您認(rèn)為將最常用的屬性。例如,Item 屬性就是集合類默認(rèn)屬性的很好的選擇,因?yàn)樗唤?jīng)常使用。

下列規(guī)則適用于VB.NET默認(rèn)屬性:

一種類型只能有一個(gè)默認(rèn)屬性,包括從基類繼承的屬性。此規(guī)則有一個(gè)例外。在基類中定義的默認(rèn)屬性可以被派生類中的另一個(gè)默認(rèn)屬性隱藏。

如果基類中的默認(rèn)屬性被派生類中的非默認(rèn)屬性隱藏,使用默認(rèn)屬性語法仍可以訪問該默認(rèn)屬性。

默認(rèn)屬性不能是 Shared 或 Private。

如果某個(gè)重載屬性是VB.NET默認(rèn)屬性,則同名的所有重載屬性必須也指定 Default。

默認(rèn)屬性必須至少接受一個(gè)參數(shù)。

下面的示例將一個(gè)包含字符串?dāng)?shù)組的屬性聲明為類的默認(rèn)屬性:

 
 
 
  1. Class Class2
  2. ' Define a local variable 
    to store the property value.
  3. Private PropertyValues As String()
  4. ' Define the default property.
  5. Default Public Property Prop1
    (ByVal Index As Integer) As String
  6. Get
  7. Return PropertyValues(Index)
  8. End Get
  9. Set(ByVal Value As String)
  10. If PropertyValues Is Nothing Then
  11. ' The array contains Nothing 
    when first accessed.
  12. ReDim PropertyValues(0)
  13. Else
  14. ' Re-dimension the array to 
    hold the new element.
  15. ReDim Preserve PropertyValues
    (UBound(PropertyValues) + 1)
  16. End If
  17. PropertyValues(Index) = Value
  18. End Set
  19. End Property
  20. End Class

訪問VB.NET默認(rèn)屬性

可以使用縮寫語法訪問默認(rèn)屬性。例如,下面的代碼片段同時(shí)使用標(biāo)準(zhǔn)和VB.NET默認(rèn)屬性語法:

 
 
 
  1. Dim C As New Class2()
  2. ' The first two lines of code 
    access a property the standard way.
  3. C.Prop1(0) = "Value One" 
    ' Property assignment.
  4. MessageBox.Show(C.Prop1(0)) 
    ' Property retrieval.
  5. ' The following two lines of 
    code use default property syntax.
  6. C(1) = "Value Two"
     ' Property assignment.
  7. MessageBox.Show(C(1))
     ' Property retrieval.

當(dāng)前文章:VB.NET默認(rèn)屬性適用規(guī)則介紹
本文鏈接:http://www.dlmjj.cn/article/dhhijod.html