Box and unbox a struct : Box Unbox : Struct C# Examples


C# Examples » Struct » Box Unbox »

 

Box and unbox a struct









    
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);
    }
    
}
    
   
  
   



Output

F


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Struct
» Box Unbox