55得票5回答
为什么在显式的只有getter的接口实现中使用私有的setter是非法的?

我倾向于采用显式接口实现而不是隐式接口实现,因为我认为针对接口进行编程通常比针对实现进行编程更好,并且在处理Web服务时经常需要这样做。 话虽如此,我想知道为什么以下内容在显式接口声明中是非法的,在隐式接口声明中却是合法的: interface IConnection { stri...

30得票9回答
如何使用反射显式获取实现接口的属性?

更具体地说,如果我有:public class TempClass : TempInterface { int TempInterface.TempProperty { get; set; } int TempInterface...

24得票3回答
类型参数'T'的名称与外部类型'...'的类型参数相同。

public abstract class EntityBase { ... } public interface IFoobar { void Foo<T>(int x) where T : EntityBase, new(); } public in...

17得票5回答
显式接口实现不能是虚拟的。

记录一下,我已经看到了这个连接项,但我实在无法理解为什么不支持这种方式。假设我有以下代码:public interface IInterface { void Method(); } public class Base : IInterface { virtual void ...

17得票4回答
为什么一个类会显式地而不是隐式地实现IDisposable接口?

我正在使用FtpWebResponse类,但没有看到Dispose方法。 原来该类显式实现了IDisposable接口,因此在调用Dispose之前,您必须将实例强制转换为IDisposable: // response is an instance of FtpWebResposne ((...

17得票2回答
F#和接口实现成员

我遇到了一个令人烦恼的错误。type Animal = abstract member Name : string type Dog (name : string) = interface Animal with member this.Name : s...

16得票2回答
C#中接口成员的访问修饰符

以下属性导致了编译错误。 错误信息是: "修饰符 'public' 对此项无效" public System.Collections.Specialized.StringDictionary IWorkItemControl.Properties { get { return ...

16得票3回答
在F#中调用基类显式接口方法

好的,我从基类A派生出一个类型B。A明确实现了IDisposable但是我还需要在B中进行额外的清理,因此我在B中实现了IDisposable:interface IDisposable with member i.Dispose() = // ... addition...

15得票3回答
为什么在值类型上调用显式接口实现会导致它被装箱?

我的问题与这个问题有些相关:如何使用泛型约束防止将具有隐式实现接口的值类型装箱?,但不同之处在于这并不需要约束,因为它根本不是泛型。 我有以下代码:interface I { void F(); } struct C : I { void I.F() {} } static class P ...

14得票2回答
为什么在泛型上进行显式接口调用时总是调用基本实现?

为什么在具有接口类型约束的泛型方法中调用显式的 C# 接口方法总是调用基础实现? 例如,请考虑以下代码: public interface IBase { string Method(); } public interface IDerived : IBase { new...