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 :: how to store more precise data then float c# 
Csharp :: how to use span c# 
Csharp :: design pattern for so many conditions c# 
Csharp :: xml reader attributes 
Csharp :: recursively fing root of tree 
Csharp :: unity debug log gameobject 
Csharp :: OOP inC# 
Csharp :: ArgumentOutOfRangeException when sorting a DataGridView using a custom IComparer 
Csharp :: nullable 
Csharp :: Web API - Stream large file to client 
Csharp :: c# return error status code based on exception 
Csharp :: Set property of control on form by name 
Csharp :: nunjucks if variable exists 
Csharp :: button pervious for picturebox c# 
Csharp :: save checkbox value to database c# 
Csharp :: wpf settings core 
Csharp :: f# set function how to ignore duplicates 
Csharp :: c# check file similarities 
Csharp :: webtest fullscreen extend window maximize 
Csharp :: c# project default namespace 
Csharp :: get current culture in controller asp.net core 6 
Csharp :: linq top selling products 
Csharp :: downloading a large file asp boilerplate (abp) 
Csharp :: An error occurred while deserializing the property of class Truncation resulted in data loss. 
Csharp :: c# execute run control panel 
Csharp :: init stirng list c# 
Csharp :: calculator using single readline c# 
Csharp :: using autofac with automapper .net 6 with dependency injection 
Csharp :: get image information using c# 
Csharp :: how to add a componet to a gameobject throgh code unity 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =