C # struct struct summary
1. Structs are value types and are sealed and cannot be inherited and derived.
2. Structure statement:
struct Structname
{
Memberdeclaration
}
struct POINT
{
public int x; Field initialization is not allowed in the structure
Pub int y;
}
3. The structure has the following characteristics
(1) structs are very similar to classes, but structs are value types and classes are reference types.
(2) struct instantiation may not be applicable to the new operator. However, after the settings data members are displayed, their values can be called.
(3) The system has provided an implicit constructor (no parameters) for the structure, so the struct declaration constructor must be a parameter.
(4) Structs do not support inheritance, and structures cannot derive from other structures.
(5) When declaring a struct, it is not allowed to assign a value at the time of initialization of the field.
4. Programming examples of structures
struct information
{
private string colour;
public string colour
{
get {return colour;}
set {colour = value;}
}
Private double hight;
Public double Hight
{
set {hight = value;}
get {return hight;}
}
private string gender;
public string Gender
{
set {gender = value;}
get {return gender;}
}
Public information (string colour, double hight, string gender)
{
Constructors with parameters, you must assign values to all variables!!
This.colour = colour;
This.gender = gender;
This.hight = hight;
}
}
Class Program
{
static void Main (string[] args)
{
Information info = new information ("Red", 180.1, "man");
Information info1 = info;
Console.WriteLine ("Colour: {0}\nhight: {1}\ngender: {2}", Info1. Colour, info1. Hight, Info1. Gender);
}
}
C # struct struct summary