473,378 Members | 1,489 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

const Array[TMyThing] of string;

Hi

In delphi we can create an array of an enum.

type
TMyEnum = (meRed, meGreen, meBlue);

const
cMyArray : array[TMyEnum] of TColor = (clRed, clGreen, clBlue);
This has the huge advantage that the compiler will actually check if enough
elements are inside the array. It is also very easy to get an element.

Color = cMyArray[FEnum];

Is there a way this can be accomplished in C#?

Kind regards

Alexander
Nov 16 '05 #1
3 2264
You can easily comvert Enum to string or value array. Just use string[]
Enum.GetNames(typeof(MyEnum))
or array Enum.GetValues(typeof(MyEnum))

Hope it helps
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Alexander Muylaert" <Re********@pandora.be> wrote in message
news:Oz*************@TK2MSFTNGP11.phx.gbl...
Hi

In delphi we can create an array of an enum.

type
TMyEnum = (meRed, meGreen, meBlue);

const
cMyArray : array[TMyEnum] of TColor = (clRed, clGreen, clBlue);
This has the huge advantage that the compiler will actually check if enough elements are inside the array. It is also very easy to get an element.

Color = cMyArray[FEnum];

Is there a way this can be accomplished in C#?

Kind regards

Alexander

Nov 16 '05 #2
No

I need to define an arry of whatever type that contains as much elements as
their are enumerations. The enumeration is also the index in the table.
This check is performed at compile time. Not at runtime. It is very
usefull for statics.

kind regards

Alexander
"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:ub*************@tk2msftngp13.phx.gbl...
You can easily comvert Enum to string or value array. Just use string[]
Enum.GetNames(typeof(MyEnum))
or array Enum.GetValues(typeof(MyEnum))

Hope it helps
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Alexander Muylaert" <Re********@pandora.be> wrote in message
news:Oz*************@TK2MSFTNGP11.phx.gbl...
Hi

In delphi we can create an array of an enum.

type
TMyEnum = (meRed, meGreen, meBlue);

const
cMyArray : array[TMyEnum] of TColor = (clRed, clGreen, clBlue);
This has the huge advantage that the compiler will actually check if

enough
elements are inside the array. It is also very easy to get an element.

Color = cMyArray[FEnum];

Is there a way this can be accomplished in C#?

Kind regards

Alexander


Nov 16 '05 #3
"Alexander Muylaert" <Re********@pandora.be> wrote:
I need to define an arry of whatever type that contains
as much elements as their are enumerations. The
enumeration is also the index in the table. This check
is performed at compile time. Not at runtime.


I'm not aware of anything like this in C#.

If I wanted to do this, I would write custom get/set functions for the
array that ensure the bounds are valid and part of the enumeration.

P.
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: selder21 | last post by:
Hello, I have a class with constructor taking a const string&. Now i want to call this constructor with a string literal. Because this is of type char* there are overload resolution conflicts....
1
by: yccheok | last post by:
Hi, consider the following bug at #include <stdio.h> class Drink { public: Drink( char *name_ ) : name( name_ ) {} char *name; char & get(int i) { return name; } };
4
by: sam | last post by:
Hi, Is there any way I can prevent people use some binary disambler (eg. strings in unix) to view the const string value in a compiled C++ program? Sam.
1
by: Erik Tamminga | last post by:
Hi, I'm totally bluffed: how can a 'public const string name = "myname";' ever evaluate to null? I have the following class: public class MIB2 { public const string org = "1.3";
6
by: ESPN Lover | last post by:
I'm fairly new to the whole .NET and OOP programming so bear with me. In the past if I wanted to have constants defined that I could use in my code, I'd include them either the file or as an...
5
by: Jae | last post by:
Real(const string &fileName) { FILE * myInputFile = fopen(fileName, "rt"); ..... fclose(myInputFile);
41
by: Dead Loop | last post by:
Hi all, I'm a beginner and my question is: Are there any differences between char *p = "Hello, world!"; and const char *p = "Hello, world!"; ?
7
by: Zytan | last post by:
I am trying to set a const string made up of Chr(), but if the value passed into Chr() is too large, the compiler complains that it is not constant!! Example: Public Const m_Data As String =...
8
by: Ook | last post by:
I have a function getStuff, and two choices of implementation: const string *getStuff() { return &_stuff; } or const string getStuff()
2
by: wizofaus | last post by:
Given the following code: public class Test { static unsafe void StringManip(string data) { fixed (char* ps = data) ps = '$'; }
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.