Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

what is the default value for an enum c#

//Default for an enum is 0.
//For example: 
using System;

public class Program
{
	
	enum EnumExample
	{
		one = 1,
		two = 2
	}
	
	public void Main()
    {		      
		var e = new EnumExample();
		
		if (e == EnumExample.one)
			Console.WriteLine("need to assign to one to get here");
		if(e == 0)
			Console.WriteLine("Will get here since the default is 0");	
    }	
}

//Output:
//Will get here since the default is 0
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #default #enum
ADD COMMENT
Topic
Name
7+3 =