Structure And Class Assignment C# with Example



Structure And Class Assignment C# with Example

 	using System;

	namespace CSharpIntermediateConstructsStruct
	{
		class Complex 
		{ 
			public int x; 
			public int y;
		}
		
		struct Real
		{ 
			public int x; 
			public int y;
		}
		
		class StructureAndClassAssignment
		{
			static void Main(string[] args)
			{
				Complex complexNumber1 = new Complex();
				complexNumber1.x = 10;
				complexNumber1.y = 20;
				Complex complexNumber2 = complexNumber1;
				complexNumber1.x = 1000;
				complexNumber1.y = 2000;
				Console.WriteLine("Class: x:{0}, y:{1}", complexNumber2.x, complexNumber2.y);
				
				Real realNumber1 = new Real();
				realNumber1.x = 100;
				realNumber1.y = 200;
				Real realNumber2 = realNumber1;
				realNumber1.x = 10;
				realNumber1.y = 20;
				Console.WriteLine("Struct: x:{0}, y:{1}", realNumber2.x, realNumber2.y);
			}
		}
	}
 

0 Comment's

Comment Form

Submit Comment