Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# enum default

enum F
{
    // Give each element a custom value
    Foo = 1, Bar = 2, Baz = 3, Quux = 0
}
Comment

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
Comment

PREVIOUS NEXT
Code Example
Csharp :: windows form textbox password 
Csharp :: C# how to use if and else 
Csharp :: recursive reverse linked list 
Csharp :: wpf messagebox result 
Csharp :: unity find object by name 
Csharp :: c# add object to array 
Csharp :: How can I return image from controller asp.net 
Csharp :: c# return task list 
Csharp :: if file exist rename c# 
Csharp :: list search c# 
Csharp :: dotnet automapper.extensions.microsoft.dependencyinjection 
Csharp :: delegate in c# 
Csharp :: unity cancel momentum 
Csharp :: how to add headers to scripts in unity 
Csharp :: find how many digits a number has 
Csharp :: c# bubble sort 
Csharp :: .net core web app get dll name 
Csharp :: asp.net core miniprofiler 
Csharp :: c# video to frames 
Csharp :: c# signalr console app client example 
Csharp :: checking a gamobjects layer 
Csharp :: how to define a function in c# 
Csharp :: c# #region #endregion 
Csharp :: c# read large file 
Csharp :: first person mouse look unity 
Csharp :: c# backup sql 
Csharp :: convert number of days into months c# 
Csharp :: autofac .net core 6 
Csharp :: defualtsize UWP c# 
Csharp :: on collision unity 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =