Can someone explain to me why this is incorrect in C#:
namespace NamespaceA
{
public class ClassA
{
public interface IInterfaceA
{
String Property
{
set;
}
}
}
}
namespace NamespaceB
{
public class ClassB
{
public class ImpA: NamespaceA.ClassA.IInterfaceA
{
private String mProperty;
public String Property{ set{ mProperty = value; } }
}
public ClassB()
{
ImpA aImpA = new ImpA();
foo(ref aImpA);
}
private void foo(ref NamespaceA.ClassA.IInterfaceA aIInterfaceA)
{
aIInterfaceA.Property = "SomeValue";
}
}
}
This will produce a compile error of:
Error Argument 1: cannot convert from 'NamespaceB.ClassB.ImpA' to 'ref NamespaceA.ClassA.IInterfaceA'
It seems perfectly reasonable to want to modify the interface properties and call the interface functions from foo()
. If you remove the ref
keyword, it compiles, but the changes you make in foo()
are lost...