Nit picking question about enum and default value. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Nit picking question about enum and default value.

In other languages I have used the default value for an enum is the first value.

enum displayType : byte
{
visible=0xa,
invisible
}

struct Points
{
public int x;
public int y;
public displayType dsp;
}
-----Main porgram-----------
Points pts = new Points();
int i = (int) dsp;
Console.WriteLine("Point 1: {0}", i);
-----------------------------
Results in a value of '0';

Question 1: What is the C# definition of the default value for a enum type?

Question 2: Should the default constructor set dsp= 0xa on creation? If so it is a bug in Visual C# 2008 express ,and I will file it. Or is the default value derived from the base type of enum in this case 'BYTE'. In which case the Visual C# is correct and the C# eBook just needs a description of how the default values are defined for enum.


Sign In or Register to comment.