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 "Profession al 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 3607
Can't say for C#, but in VB.NET:
Public Enum something As IntegerBasedTyp e
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*******@gmai l.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.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 "Profession al 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*******@gmai l.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.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 "Profession al 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*******@gmai l.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=100000 0,
...
...
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*********@mv ps.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*********@mv ps.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 indexer. There are
problems with this however. First the indexer "override" has a different
return type. This doesn't cause a compile time error,...
|
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, Int, Float, etc...)
2. VB 6 and VBScript were not strongly typed because both allowed you to ...
dim blah
.... which creates a variant.
|
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 Web Service it adds
another Table to the DataSet that contains the data. I have to access
the data using ds.Tables.Rows.ToString(). This
defeats the...
|
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 arraylist then I have to handle this
with a sort method that uses comparer. I can reference the properties of the
Arraylist directly such as
dim...
| |
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, 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...
|
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 to URLs in a strongly
typed fashion. Something like:
this.Response.Redirect(URLs.Index_ASPX);
|
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 myTable";
using (SqlConnection conn = new SqlConnection(websqlconn))
{
SqlCommand cmd = new SqlCommand(sql, conn);
|
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 comparisions) cleared?
Thanks,
Rachana
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |