Use enum data type in a struct : struct definition « struct « C# / CSharp Tutorial






using System;

enum EmpType : byte 
{
  Manager = 10,
  Developer = 1,
  Contractor = 100,
  Programmer = 9
}

struct EMPLOYEE 
{
  public EmpType title;
  public string name;
  public short deptID;

  public EMPLOYEE(EmpType et, string n, short d)
  {
    title = et;
    name = n;
    deptID = d;
  }
}

class MainClass
{
  public static void Main(string[] args) {
    EMPLOYEE fred;
    fred.deptID = 40;
    fred.name = "Fred";
    fred.title = EmpType.Developer;

    EMPLOYEE mary = new EMPLOYEE(EmpType.Programmer, "Mary", 10);

  }
}








6.2.struct definition
6.2.1.Declare the Rectangle struct
6.2.2.Declaration of a struct and use it
6.2.3.Declare a struct
6.2.4.Use enum data type in a struct
6.2.5.Composite Struct
6.2.6.Create A Struct Using Default Constructor
6.2.7.Defining struct