default Keyword C# with Example



default Keyword C# with Example

 	using System;

	namespace CSharpGenerics
	{	
		class BaseClass{}
		class GenClass
		{
			public T genObject;
			
			public GenClass()
			{
				genObject = default(T);
			}
		}
				
		class defaultKeyword
		{
			static void Main( )
			{
				GenClass valType = new GenClass();
				if(valType.genObject == 0)
					Console.WriteLine("Default Value for Value Type: 0");
				
				GenClass refType = new GenClass();
				if(refType.genObject == null)
				Console.WriteLine("Default Value for Reference Type: null");
			}
		}
	}
 

0 Comment's

Comment Form

Submit Comment