Quick Question

M

Mike

Hi,

I am using an enum to map to certain columns instead of using the string
name. When I use the enum as the indexer in a datarow it forces me to cast
it into an int. Shouldn't this be automatic at design time? See code
below:

private enum DataIndexer
{
OrderID,
SerialNumber
};

orderID = (string)currentRow[(int)DataIndexer.OrderID];
serialNumber = (string)currentRow[(int)DataIndexer.SerialNumber];

Why not this:

rderID = (string)currentRow[DataIndexer.OrderID];
serialNumber = (string)currentRow[DataIndexer.SerialNumber];

Thanks
 
J

Joel Hendrix [MSFT]

The C# language spec states that an explicit cast is required to convert
between an enum type and an integral type.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html
/vclrfCSharpSpec_14_5.asp

-Joel
--------------------
From: "Mike" <[email protected]>
Subject: Quick Question
Date: Mon, 7 Jun 2004 11:35:11 -0600
Lines: 24
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: 64.207.45.37
Path: cpmsftngxa10.phx.gbl!TK2MSFTFEED02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP0
8.phx.gbl!TK2MSFTNGP09.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.languages.csharp:249628
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

Hi,

I am using an enum to map to certain columns instead of using the string
name. When I use the enum as the indexer in a datarow it forces me to cast
it into an int. Shouldn't this be automatic at design time? See code
below:

private enum DataIndexer
{
OrderID,
SerialNumber
};

orderID = (string)currentRow[(int)DataIndexer.OrderID];
serialNumber = (string)currentRow[(int)DataIndexer.SerialNumber];

Why not this:

rderID = (string)currentRow[DataIndexer.OrderID];
serialNumber = (string)currentRow[DataIndexer.SerialNumber];

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top