How to Declare Structure and Assign the Value and Call in C#

  1. using System.IO;  
  2. using System;  
  3. class Complex   
  4. {  
  5.     public int x;  
  6.     public int y;  
  7. }  
  8. struct Real   
  9. {  
  10.     public int x;  
  11.     public int y;  
  12. }  
  13. class StructureAndClassAssignment   
  14. {  
  15.     static void Main(string[] args)   
  16.     {  
  17.         Complex complexNumber1 = new Complex();  
  18.         complexNumber1.x = 10;  
  19.         complexNumber1.y = 20;  
  20.         Complex complexNumber2 = complexNumber1;  
  21.         complexNumber1.x = 1000;  
  22.         complexNumber1.y = 2000;  
  23.         Console.WriteLine("Class: x:{0}, y:{1}", complexNumber2.x, complexNumber2.y);  
  24.         Real realNumber1 = new Real();  
  25.         realNumber1.x = 100;  
  26.         realNumber1.y = 200;  
  27.         Real realNumber2 = realNumber1;  
  28.         realNumber1.x = 10;  
  29.         realNumber1.y = 20;  
  30.         Console.WriteLine("Struct: x:{0}, y:{1}", realNumber2.x, realNumber2.y);  
  31.     }  
  32. }
Output:

Class: x:1000, y:2000
Struct: x:100, y:200