Multiple Constraints C# with Example



Multiple Constraints C# with Example

 	using System;

	namespace CSharpGenerics
	{	
		class GenClass where T : class where V : struct
		{
			T referenceObject;
			V valueObject;
			
			public GenClass(T argTObject, V argVObject)
			{
				referenceObject = argTObject;
				valueObject = argVObject;
			}
			
			public void DisplayMessage()
			{
				Console.WriteLine("Name: {0}", referenceObject);
				Console.WriteLine("Salary: {0} PA", valueObject);
			}
		}
				
		class UsingMultipleConstraints
		{
			static void Main( )
			{
				GenClass refType = new GenClass("Kuldeep", 600000);
				refType.DisplayMessage();
			}
		}
	}
 

0 Comment's

Comment Form

Submit Comment