struct: the equivalent of a complex type that we define ourselves.
Int... Double float bool Char string DateTime array type
Most of the objects in life are complex objects.
How do I define a struct type?
In general, the definition of the structure should be placed outside the class or inside the class, try not to put in the inside of main.
struct Custom type name
{
Public variable type variable name; ......; ......; ......;
}
For example:
struct Yuangong//custom data type. Information used to describe an employee.
{
public string NO;
public string Name;
public int age;
public string Nation;
public bool Sex;
}
How do I define a variable with a custom type? Custom type name variable = new custom type name ();
How do I use a variable of a custom type?
Variable. Sub variable = "xxxx"; Console.WriteLine (variable name. sub-variable);
For example:
Define a variable of a custom type
Yuangong Zhangsan = new Yuangong ();
Assigning values to variables
zhangsan.no = "Y001";
Zhangsan. Name = "Zhang San";
Zhangsan. age = 22;
Zhangsan. Sex = true;
Zhangsan. Nation = "Han";
To value a variable
Console.WriteLine (zhangsan.no+ "\ t" +zhangsan. Name+ "\ t" +zhangsan. Age);
Console.WriteLine (Zhangsan. nation+ "\ T" + (Zhangsan. "Sex?" Male ":" female "));
C # struct BODY