Differences Between Enums in C# and VB.NET?

A method call is not a constant expression. Try this.

A method call is not a constant expression. Try this: public enum Status { Open = 'O', Closed = 'C', Pending = 'P', EnRoute = 'E' } The reason AscW works in VB is that it's an internal thing that VB compiler understands and evaluates at compile time and is considered a constant expression by the compiler. Even in VB, Convert.

ToInt32 will not work. To quote the Visual Basic specification: 11.2 Constant Expressions A constant expression is an expression whose value can be fully evaluated at compile time. ... The following constructs are permitted in constant expressions: ... The following run-time functions: Microsoft.VisualBasic.Strings.

ChrW Microsoft.VisualBasic.Strings. Chr, if the constant value is between 0 and 128 Microsoft.VisualBasic.Strings. AscW, if the constant string is not empty Microsoft.VisualBasic.Strings.

Asc, if the constant string is not empty.

Well I guess it could not be much easier than this :) Thank you! – Josh Stodola Jan 14 '10 at 16:10 +1 and accepted, especially because you included why my sample code works in VB. Thank you, Mehrdad.

– Josh Stodola Jan 14 '10 at 16:11 3 Nick: It doesn't really matter that it's declared in Microsoft.VisualBasic. The key thing is the compiler is hard-wired to understand AscW and it's not really calling any methods at run time. It just replaces the expression with its integral value at compile time.

– Mehrdad Afshari Jan 14 '10 at 16:21 2 +1, It's slightly more complicated than that. AscW is both well understood by the compiler and a feature of the VB runtime. In the case of a constant and valid expression, the compiler will optimize out the AscW call.

But in cases where it's not constant or not understood, it will defer to the VB runtime. – JaredPar Jan 14 '10 at 16:39 1 @Josh: VB. NET (unlike C#) does not support implicit coercions from character to integers.

This design decision makes simply writing "EnumMember = "A"c not work. It's not really a matter of ease of implementation. – Mehrdad Afshari Jan 14 '10 at 18:33.

Try this: public enum Status { Open = 'O', Closed = 'C', Pending = 'P', EnRoute = 'E' }.

Thank you, yes I will up-vote this too becuase there was only seconds apart in your answers. You guys are fast! – Josh Stodola Jan 14 '10 at 16:12.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send