Arrays and interfaces based on c use the example of to traverse a set of two dimensional arrays

  • 2020-06-01 10:55:52
  • OfStack

1. Initialize the array:


string[] s1 = { " aaa " , " bbb " , " ccc " }   // Direct assignment 
string[] s2 = new string[5] { " aaa " , " bbb " , " ccc " }; // Assignment plus specified length 
string[] s3 =  new string[]{ " aaa " , " bbb " , " ccc " }; 
string[] s4 = new string[5];  // Direct assignment with a loop 

2. Traversal groups:


foreach (string s in str)
{
  Console.Write(s);
}

3. 2-d array:

string [and] arr2; // declares a 2-dimensional array
string [and] arr3; // declares a multidimensional array
4. Jagged array:
An array with different lines for each 1.

5. The interface

You can use the new modifier to hide the interface inherited from the base class


public class Class2:Class1
{
  new public interface Iinterface
  {
  void Print();
  }
}

Inherit multiple interfaces:


public interface Iinterface3 : Iinterface1, Iinterface2, Iinterface3
{
  void Print3();
}

Interface properties, methods, etc., can not be implemented, can only be declared. Such as:


public interface Iinterface
{
  string Name
  {
  get;
  set;
  }
}

Implementation interface:
public class Program : Iinterface
Abstract classes and interfaces:
Abstract class features: cannot be sealed, cannot be instantiated directly, and can contain abstract members

Differences between abstract classes and interfaces:
A class can implement multiple interfaces, but can only have one parent class;
Interfaces cannot contain non-abstract methods, but they can exist in abstract classes.
Abstract class is an incomplete class, and interface is a behavior specification.
Interfaces don't have any of the basic features of inheritance, they just promise methods that can be called.


Related articles: