假设我已经定义了两个不相关的类型和两个具有相同签名但不同类型过滤器的扩展方法:
public class Foo {}
public class Bar {}
public static class FooExtensions
{
public static TFoo Frob<TFoo>(this TFoo foo) where TFoo : Foo { }
public static TFoo Brob<TFoo>(this TFoo foo) where TFoo : Foo { }
}
public static class BarExtensions
{
public static TBar Frob<TBar>(this TBar bar) where TBar : Bar { }
}
Run Code Online (Sandbox Code Playgroud)
然后,当我写作时,new Foo().Frob();我得到一个错误
error CS0121: The call is ambiguous between the following methods or properties: 'FooExtensions.Frob<TFoo>(TFoo)' and 'BarExtensions.Frob<TBar>(TBar)'
有人可以解释为什么这会失败以及如何避免它?
编辑:这发生在VS2015 Update 3和VS2017 …
有一天,我正在向我的一个朋友咆哮一个特定的Telerik控件.我告诉他生成一个控制树花了几秒钟,在分析后我发现它在循环中使用字符串连接而不是StringBuilder.重写后,它几乎是瞬间完成的.
所以我的朋友听说过,并且似乎很惊讶C#编译器没有像Java编译器那样自动进行转换.阅读Eric Lippert的许多答案,我意识到这个功能没有成功,因为它不值得考虑.但是,如果假设成本实现它的成本很小,那么什么理由会阻止人们去做呢?
看来打字稿会忽略JavaScript文件的标签设置,并在生成的js文件中插入空格而不是标签。
有设置强制制表符而不是空格的设置吗?
使用VS 2013 Update 4的PS