Box and unbox a struct : Box Unbox « struct « C# / CSharp Tutorial






using System;

struct EMPLOYEE 
{
  public string name;
  public short deptID;

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

class MainClass
{
  public static void Main(string[] args) {
    EMPLOYEE fred = new EMPLOYEE("s",1);
    fred.name = "F";

    object stanInBox = fred;
  
    UnboxThisEmployee(stanInBox);
  }
  public static void UnboxThisEmployee(object o)
  {
    EMPLOYEE temp = (EMPLOYEE)o;
    Console.WriteLine(temp.name);
  }
  
}
F








6.14.Box Unbox
6.14.1.Box and unbox a struct
6.14.2.Box a struct, change its value and unbox it
6.14.3.Box struct to call its implemented interface