我需要什么命名空间才能让我的扩展正常工作
这是我的扩展方法
using System; using System.Collections.Generic; using System.Web; using System.Data; namespace MyUtilities { public static class DataReaderExtensions { public static DataTable ToDataTable(IDataReader reader) { DataTable table = new DataTable(); table.Load(reader); return table; } } }
当我尝试像这样使用它时
Session["Master"] = cust.GetCustomerOrderSummary((string)Session["CustomerNumber"]).ToDataTable();
这是行不通的。这是 .net 2.0
最佳答案
你不能。 C# 2.0 根本没有扩展方法。您可以在 Visual Studio 2008 中使用 C# 3.0 的扩展方法targeting .NET 2.0,如我的 "C#/.NET versions" article 中所述但您无法说服 C# 2.0 编译器表现得好像它了解什么是扩展方法。
关于c# - C# 2.0 中的扩展方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/707145/