1. References to InterfacesWe cannot access interfaces directly through the members of a class object, and can be cast to an interface type through a class object reference to obtain a reference to an interface. with the reference to the interface, you can use the dot number to invoke the method of the interface
Understanding: This is a concept of polymorphism, after assigning the object to the interface, through a unified interface name access can achieve a variety of behavior
2. Use the Return interface method (increase the flexibility of the method so that the orientation can have properties and methods like an object)Public IEnumerator GETNUMERAOTR ();This method returns an object that inherits the IEnumerator interface, and can invoke the extension method or property of the interface through the return value of the function.Getnumerator (). The current property can return a value.C # uses several basic concepts to iterate over complex functions iteratively, and then use complex functions to develop more complex functions.
Common Interfaces
static void Main(string[] args)
{
using (CaryClass caryClass = new CaryClass()) // IDisposeable接口用using来调用
{
caryClass.DoSomething();
}
CaryClass caryClass2 = new CaryClass();
try
{
caryClass2.DoSomething();
}
finally // use finally to make an excuse call
{
IDisposable disposable = caryClass2 as IDisposable;
if (disposable != null)
disposable.Dispose();
}
Console.ReadKey();
}
}
public class CaryClass : IDisposable
{
public void DoSomething()
{
Console.WriteLine("Do some thing....");
}
public void Dispose()
{
Console.WriteLine("及时释放资源");
}
}
From for notes (Wiz)
Basic concepts of interfaces in C #