67得票8回答
扩展方法语法与查询语法

我正在努力理解何时使用标准的LINQ关键字或带有Lambda表达式的LINQ扩展方法更好。它们似乎做着相同的事情,只是书写方式不同。这纯粹是风格问题吗?var query = from p in Products where p.Name.Contains("foo") ord...

64得票5回答
Scala中等价于C#扩展方法的东西是什么?

在C#中,你可以写成:using System.Numerics; namespace ExtensionTest { public static class MyExtensions { public static BigInteger Square(this BigInteger ...

64得票6回答
在编译时检测目标框架版本

我有一些使用扩展方法的代码,但是在使用VS2008编译器编译的.NET 2.0下运行。为了实现这一点,我不得不声明ExtensionAttribute:/// <summary> /// ExtensionAttribute is required to define extens...

63得票6回答
Python中的扩展方法

Python有像C#那样的扩展方法吗?是否可以调用这样的方法:MyRandomMethod() 在现有的类型(如int)上进行操作?myInt.MyRandomMethod()

63得票14回答
扩展方法未被识别

当从外部引入一个扩展方法时,为了使其生效,需要哪些条件?我在类库项目中编写了一个扩展方法,但是我的Web项目无法识别它。尽管类库中的所有其他类和方法都能被识别和使用,但是这个扩展方法却不能。在类库内部使用时可以看到该扩展方法。

61得票8回答
Python扩展方法

好的,在C#中我们有类似这样的东西:public static string Destroy(this string s) { return ""; } 基本上,当你有一个字符串时,你可以这样做:str = "This is my string to be destroyed"; n...

59得票16回答
在使用C#扩展方法时出现错误

我遇到了一个问题,让我觉得 3.0 框架中有一个 bug。当我尝试使用扩展方法时,会出现以下错误: I came across an issue that makes me think there is bug in the 3.0 framework. When I try to use e...

58得票8回答
在“null”引用(即没有订阅者的事件)上调用扩展方法是否邪恶?

邪恶还是不邪恶?public static void Raise(this EventHandler handler, object sender, EventArgs args) { if (handler != null) { handler(sender, arg...

56得票2回答
如何在TypeScript中为“Date”数据类型创建扩展方法?

我试图基于这个讨论(https://github.com/Microsoft/TypeScript/issues/9)来创建一个TypeScript扩展方法,但我无法创建一个可用的方法。以下是我的代码,namespace Mynamespace { interface Date { ...

56得票13回答
什么是扩展方法?

.NET 中的扩展方法是什么? 编辑: 我在使用扩展方法上发布了一个后续问题。