.net - VB.NET 扩展方法

标签 .net vb.net extension-methods

当我在方法上方应用标签时,出现错误

Type System.Runtime.CompilerServices.Extension is not defined.



这是我的样本
<System.Runtime.CompilerServices.Extension()> _
     Public Sub test()

End Sub

我哪里错了?

编辑 ~ 直接来自 MSDN 文章 here ,同样的错误
Imports System.Runtime.CompilerServices

Module StringExtensions
     _
  Public Sub Print(ByVal aString As String)
        Console.WriteLine(aString)
    End Sub

End Module


我在我的项目中使用 Visual Studio 2008 和 3.5 Framework。

Solution ~ The project was on 2.0 Framework. Changed to 3.5 and it works.

最佳答案

IDE 指向哪个版本的 .net 框架?

此外,乍一看,扩展方法的语法看起来不正确。

代码不完整。请将 using 语句放在示例中,以便任何人使用代码并编译它 - 重现错误。

关于.net - VB.NET 扩展方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/332810/

相关文章:

c# - 分开一个长字符串

c# - 每个请求的连接

c# - 无法将 Microsoft Office Interop 程序集添加到项目中

asp.net - WCF 服务绑定(bind)设置

.net - 我可以同时运行多少个线程?

c# - 将此 DLL 包含从 VB.net 翻译成 C#

java - 流形和结构

vb.net - Meitrack设备返回什么来确认服务器收到的数据

c# - 将 Enumerable.ToDictionary 与扩展方法一起使用时为 "CLR detected an Invalid Program"

ios - 为什么 SwiftUI 中的 Today App Extension Widget 是白色的?