class vs struct : Struct : Struct C# Examples


C# Examples » Struct » Struct »

 

class vs struct









    
using  System;
using  System.Collections.Generic;
using  System.Text;



class  MyClass  {
        public  int  val;
}

struct  myStruct  {
        public  int  val;
}

class  Program  {
        static  void  Main(string[]  args)  {
                MyClass  objectA  =  new  MyClass();
                MyClass  objectB  =  objectA;
                objectA.val  =  10;
                objectB.val  =  20;
                myStruct  structA  =  new  myStruct();
                myStruct  structB  =  structA;
                structA.val  =  30;
                structB.val  =  40;
                Console.WriteLine("objectA.val  =  {0}",  objectA.val);
                Console.WriteLine("objectB.val  =  {0}",  objectB.val);
                Console.WriteLine("structA.val  =  {0}",  structA.val);
                Console.WriteLine("structB.val  =  {0}",  structB.val);
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Struct
» Struct