Interfaces in .Net a Value Type or a Reference Type
Interface methods can’t contain any implementation; hence, interface types are incomplete
abstract. Also Interfaces dont derive from System.Object or any derived type. Interfaces can be implemented by Reference types as well as Value types. Actually CLR treats interfaces in a different way.
Same interface can be implemented by value stype and reference type. For Example -
This shows that an interface is nothing more than declaration and its behaviour will depend whether a value type implements it or a reference type.
abstract. Also Interfaces dont derive from System.Object or any derived type. Interfaces can be implemented by Reference types as well as Value types. Actually CLR treats interfaces in a different way.
Same interface can be implemented by value stype and reference type. For Example -
public interface ISampleInterface
{
int MYProp1 { get; set; }
void DoWork1();
}
public struct SampleStruct1 : ISampleInterface
{ public int MYProp1 { get { return 0; } set { } }
public void DoWork1() { }
}
public class SampleClass1 : ISampleInterface
{
public int MYProp1 { get { return 0; } set { } }
public void DoWork1() { }
}
ISampleInterface t = new SampleStruct1();
MessageBox.Show(t.ToString());
//result - "SampleStruct1"
ISampleInterface t1 = new SampleClass1();
MessageBox.Show(t1.ToString());
//result - "SampleClass1"
This shows that an interface is nothing more than declaration and its behaviour will depend whether a value type implements it or a reference type.


0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home