I forgot the syntax for strongly typed enums in .NET. I know C#
supports them. Not sure if strong-typing of enums is CLS compliant but,
can you refresh my memory with the C# syntax and VB syntax, please?
I've been looking in "Professional C#" to no avail yet. I don't
remember where I saw the syntax on an earlier occassion. This is just a
small thing I am trying to memorize. 7 1075
Can't say for C#, but in VB.NET:
Public Enum something As IntegerBasedType
item = number
item= number
item= number
item= number
etc.
End Enum
Note that it is not necessary to manually assign numeric values if you don't
want to. In that case, the values will automatically assigned Integer
values starting from zero.
"Sathyaish" <sa*******@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com... I forgot the syntax for strongly typed enums in .NET. I know C# supports them. Not sure if strong-typing of enums is CLS compliant but, can you refresh my memory with the C# syntax and VB syntax, please?
I've been looking in "Professional C#" to no avail yet. I don't remember where I saw the syntax on an earlier occassion. This is just a small thing I am trying to memorize.
The C# language spec contains information on the enum. http://msdn.microsoft.com/library/de...pspec_14_3.asp
--
Tim Wilson
..NET Compact Framework MVP
"Sathyaish" <sa*******@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com... I forgot the syntax for strongly typed enums in .NET. I know C# supports them. Not sure if strong-typing of enums is CLS compliant but, can you refresh my memory with the C# syntax and VB syntax, please?
I've been looking in "Professional C#" to no avail yet. I don't remember where I saw the syntax on an earlier occassion. This is just a small thing I am trying to memorize.
"Sathyaish" <sa*******@gmail.com> schrieb: I forgot the syntax for strongly typed enums in .NET. I know C# supports them. Not sure if strong-typing of enums is CLS compliant but, can you refresh my memory with the C# syntax and VB syntax, please?
In addition to the other replies, yes, enumeration types are CLS compilant.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Thanks, everybody.
Just for any one else looking for the same information later, the
syntax, as given by the C# specification is:
enum EnumerationName: DataType
{
elementOne;
elementTwo;
}
e.g.
enum NumeralOrders: uint32
{
tens=10,
hundreds=100,
....
....
millions=1000000,
...
...
thingamajillion=1000000000000
}
Sathyaish wrote: I forgot the syntax for strongly typed enums in .NET. I know C# supports them. Not sure if strong-typing of enums is CLS compliant but, can you refresh my memory with the C# syntax and VB syntax, please?
Also, I should point out that in C#, all enums are "strongly-type" which
means that a varaible declared as an enum type, can only be that enum type:
enum ABC {A, B, C}
enum XYZ {X, Y, Z}
public static void Main()
{
ABC abc = XYZ.X; // error
ABC def = 2; // error
}
I assume what you are actually after is not a "Strongly-typed enum", but "an
enum with a user-specified underlying type"
--
Truth,
James Curran [erstwhile-MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
"James Curran" <Ja*********@mvps.org> schrieb: I forgot the syntax for strongly typed enums in .NET. I know C# supports them. Not sure if strong-typing of enums is CLS compliant but, can you refresh my memory with the C# syntax and VB syntax, please?
Also, I should point out that in C#, all enums are "strongly-type" which means that a varaible declared as an enum type, can only be that enum type:
This applies to VB.NET with 'Option Strict On' too.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
"James Curran" <Ja*********@mvps.org> wrote Also, I should point out that in C#, all enums are "strongly-type" which means that a varaible declared as an enum type, can only be that enum type:
enum ABC {A, B, C} enum XYZ {X, Y, Z} public static void Main() { ABC abc = XYZ.X; // error ABC def = 2; // error }
Yes, but you can do this:
enum ABC {A, B, C}
public static void Main()
{
ABC abc = (ABC)42; // no error
}
From the C# spec (14.5): "The set of values that an enum type can take on is
not limited by its enum members. In particular, any value of the underlying
type of an enum can be cast to the enum type, and is a distinct valid value
of that enum type." http://msdn.microsoft.com/library/de...pspec_14_5.asp
Regards,
Marcus This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Bill Cohagan |
last post by:
I'm trying to figure out the "best" way to implement a strongly typed
ArrayList. Using inheritance is one approach. It has the advantage that I
only have to write overrides for the Add method and...
|
by: Job Lot |
last post by:
I am confused how strongly typed dataset is different from un-typed dataset.
Is there any good link explaining pros and cons of both? Which one should be
used preferably?
|
by: Mark |
last post by:
Just wanted to confirm that my understanding of a strongly typed language is
correct:
1. .NET is a strongly typed language because each variable / field must be
declared a specific type (String,...
|
by: HardBap |
last post by:
I've created a strongly typed DataSet (Customers.xsd) using the xsd.exe
tool. I want to be able to access fields using
ds.Customer.CompanyName.
The problem is when I return this DataSet from a...
|
by: Sathyaish |
last post by:
I forgot the syntax for strongly typed enums in .NET. I know C#
supports them. Not sure if strong-typing of enums is CLS compliant but,
can you refresh my memory with the C# syntax and VB syntax,...
|
by: Dennis |
last post by:
I use the following code for a strongly typed arraylist and it works great.
However, I was wondering if this is the proper way to do it. I realize that
if I want to implement sorting of the...
|
by: Polaris431 |
last post by:
In code, you can type the following:
this.Response.Redirect("~/index.aspx");
Is there anything in ASP.NET that you can use in place of strings when
referring to URLs? It would be nice to refer...
|
by: Code Monkey |
last post by:
Silly question maybe, but I've been doing the following for far too
long now:
public static DataTable myDataTable()
{
string sql = @"SELECT column1, column2, column3, column4
FROM...
|
by: Rachana |
last post by:
Hi,
I have understood Data Sets but what is meant by typed/untyped/
strongly typed datasets. Can any one explain me or suggest any site/
article, to get these concepts (and their ...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |