假设我有以下代码:
class Foo: IFoo {
public string fooProp { get; set; }
}
interface IFoo {
string fooProp {get; set; }
}
是否有可能在以下情况之间存在不同的行为:
Foo x = new Foo();
someMethod(x);
和:
IFoo x = new Foo();
someMethod(x);
?
最佳答案
我认为可能有所不同。如果有人使用了糟糕的编程风格,即:
public void someMethod(IFoo f)
{
if (f is Foo)
{
Foo f1 = (Foo)f;
//Do smth with unique Foo members
}
//Do anything with IFoo members
}
关于c# - 接口(interface)有什么方法可以导致不同的行为吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13731889/