共用方式為


BC36550:'Extension' 屬性只能套用至 'Module'、'Sub' 或 'Function' 宣告

在 Visual Basic 中擴充數據類型的唯一方法是在標準模組內定義擴充方法。 擴充方法可以是 Sub 程式或 Function 程式。 所有擴充方法都必須以命名空間中的System.Runtime.CompilerServices擴充屬性<Extension()>標記 。 或者,包含擴充方法的模組可能會以相同方式標記。 沒有其他擴充屬性的使用有效。

錯誤標識碼: BC36550

更正這個錯誤

  • 拿掉擴充屬性。

  • 重新設計延伸模組做為方法,定義於封入模組中。

範例

下列範例會 Print 定義數據類型的方法 String

Imports StringUtility
Imports System.Runtime.CompilerServices
Namespace StringUtility
    <Extension()>
    Module StringExtensions
        <Extension()>
        Public Sub Print (ByVal str As String)
            Console.WriteLine(str)
        End Sub
    End Module
End Namespace

另請參閱