new Constructor Interface Constraint C# with Example



new Constructor Interface Constraint C# with Example

 	using System;

	namespace CSharpGenerics
	{
		class BaseClass{}
		class OtherClass{}
		
		class GenClass where T : new()
		{
			T genObject;
			
			public GenClass()
			{
				genObject = new T();
			}
			
			public void DisplayMessage()
			{
				Console.WriteLine(genObject);
			}
		}
		
		class newConstructorInterfaceConstraint
		{
			static void Main( )
			{
				GenClass genBaseObject = new GenClass();
				genBaseObject.DisplayMessage();
				
				GenClass genOtherObject = new GenClass();
				genOtherObject.DisplayMessage();
			}
		}
	}
 

0 Comment's

Comment Form

Submit Comment