Interfaces (interface)
In this course, we mainly learn about the features and use of interfaces in C #. In my opinion, interfaces are very much like abstract classes but different, or excuses are an escalation of abstract classes.
The main difference between interface and abstract class: interface can be placed anywhere in the program layer, and the abstract class can only be placed at the top. 、
declaring interfaces:
public interface Istorable
{
void Read ();
void Write (object);
}
Using interfaces:
public class Document:istorable
{
public void Read () {...}
public void Write (object obj) {...}
// ...
}
As we can see, the interface only writes function signatures when declaring, and cannot be implemented. When using an interface, all functions in the interface need to be implemented in the corresponding class, or the compiler will make an error.
It is important to note that multiple interfaces can be inherited at the same time
public class document:istorable, icompressible
Also, interfaces can be inherited directly, meaning that interfaces can be combined.
public interface C:a,b (where A,b,c is the interface name)
{
......
}
Description of the keyword as: A as B, the left operand is converted to the right operand, and if B is an interface of a, it can be converted. No, the null value is returned.
Array
Statement: type [] arry-name;
Keyword params
When used, it is placed before the parameters of the function definition.
public void Displayvals (params int[] intvals)
{...; }
When you call this function, you can write an array of items without writing the array in parentheses.
C # after-school mini-Test 4