Generic Structure C# with Example



Generic Structure C# with Example

 	using System;

	namespace CSharpGenerics
	{	
		struct Coordinate 
		{
			T x;
			T y;

			public Coordinate(T a, T b) 
			{
				x = a;
				y = b;
			}

			public T X 
			{
				get { return x; }
				set { x = value; }
			}

			public T Y 
			{
				get { return y; }
				set { y = value; }
			}
		}
		
		class defaultKeyword
		{
			static void Main( )
			{
				Coordinate screen = new Coordinate(10, 20);
				Coordinate monitor = new Coordinate(88.0, 99.0);
				Console.WriteLine("Pixel Position on Screen: " + screen.X + ", " + screen.Y);
				Console.WriteLine("Pixel Position on Monitor: " + monitor.X + ", " + monitor.Y);
			}
		}
	}
 

0 Comment's

Comment Form

Submit Comment