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!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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

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.