Hi,
I'm looking for a way to associate multiple "lists" of constants to each
other.
For example, I'd like a way to look up a database column's name based on its
"number" in a constants list.
I'm new to C# and my background is in Delphi, so below is an example of how
I would declare such a constant array of records in Delphi.
__________________________________________________ ____
Type
TDBField =
Record
Number : Integer;
Name : String;
Description : String;
End;
Const
gcaDBFields : Array [0..2] Of TDBField =
(
(Number: 0; Name: ''; Description : ''),
(Number: 1000; Name: 'Field1'; Description: 'Field 1 Description'),
(Number: 2000; Name: 'Field2'; Description: 'Field 2 Description')
);
__________________________________________________ ____
How do I accomplish the same in C#?
Thanks,
Erik 3 2206
Hi,
Im affraid, that C# arrays can not be declared as const.
The only solution i see:
public readonly static TDBField[] gcaDBFields = new TDBField[] {
new TDBField(....)
, new TDBField(....)
, new TDBField(....) };
This sample needs parametrized contructor for TDBField structure.
Regards
Marcin Hi,
I'm looking for a way to associate multiple "lists" of constants to each other. For example, I'd like a way to look up a database column's name based on its "number" in a constants list.
I'm new to C# and my background is in Delphi, so below is an example of how I would declare such a constant array of records in Delphi. __________________________________________________ ____
Type TDBField = Record Number : Integer; Name : String; Description : String; End;
Const gcaDBFields : Array [0..2] Of TDBField = ( (Number: 0; Name: ''; Description : ''), (Number: 1000; Name: 'Field1'; Description: 'Field 1 Description'), (Number: 2000; Name: 'Field2'; Description: 'Field 2 Description') ); __________________________________________________ ____
How do I accomplish the same in C#?
Thanks, Erik
>> public readonly static TDBField[] gcaDBFields
The gcaDBFields is not really readonly, the client code can still change the
element of that array.
To get a real constant array-like object, use ReadOnlyCollection instead of
an array.
"Marcin Grzębski" <mg*******@taxussi.no.com.spam.pl> ????
news:d4**********@nemesis.news.tpi.pl... Hi,
Im affraid, that C# arrays can not be declared as const. The only solution i see:
public readonly static TDBField[] gcaDBFields = new TDBField[] { new TDBField(....) , new TDBField(....) , new TDBField(....) };
This sample needs parametrized contructor for TDBField structure.
Regards Marcin
Hi,
I'm looking for a way to associate multiple "lists" of constants to each other. For example, I'd like a way to look up a database column's name based on
its "number" in a constants list.
I'm new to C# and my background is in Delphi, so below is an example of
how I would declare such a constant array of records in Delphi. __________________________________________________ ____
Type TDBField = Record Number : Integer; Name : String; Description : String; End;
Const gcaDBFields : Array [0..2] Of TDBField = ( (Number: 0; Name: ''; Description : ''), (Number: 1000; Name: 'Field1'; Description: 'Field 1 Description'), (Number: 2000; Name: 'Field2'; Description: 'Field 2 Description') ); __________________________________________________ ____
How do I accomplish the same in C#?
Thanks, Erik
smartkid wrote: public readonly static TDBField[] gcaDBFields
The gcaDBFields is not really readonly, the client code can still change the element of that array.
To get a real constant array-like object, use ReadOnlyCollection instead of an array.
You're right only gcaDBFields can not be assigned in user code
but all fields are not read-only.
It's a pity, if there is no simpler declaration of constant array :-(
Thank You & Regards
Marcin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: maniac |
last post by:
Hey guys, I'm new here, just a simple question.
I'm learning to Program in C, and I was recommended a book called,
"Mastering C Pointers", just asking if any of you have read it,
and if it's...
|
by: copx |
last post by:
I want to save a struct to disk.... as plain text.
At the moment I do it with a function that just
writes the data using fprintf. I mean like this:
fprintf(fp, "%d %d", my_struct.a, my_struct.b)...
|
by: Randy Yates |
last post by:
In Harbison and Steele's text (fourth edition, p.111)
it is stated,
The C language does not specify the range of integers that the
integral types will represent, except ot say that type int may...
|
by: infobahn |
last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
|
by: Simon Morgan |
last post by:
I hope this isn't OT, I looked for a newsgroup dealing purely with
algorithms but none were to be found and seeing as I'm trying to implement
this in C I thought this would be the best place.
I...
|
by: Matt |
last post by:
I want to know if "int" is a primitive type, or an object?
For example, the following two approaches yield the same result.
> int t1 = int.Parse(TextBox2.Text); //method 1
> int t2 =...
|
by: Chris Strug |
last post by:
Hi,
I'm working with VB 2005.net and have managed to get my head around passing
values between forms by creating properties of the relevant form classes.
However, say that I have a number of...
|
by: spibou |
last post by:
Why is a pointer allowed to point to one position past
the end of an array but not to one position before the
beginning of an array ? Is there any reason why the
former is more useful than the...
|
by: raylopez99 |
last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to
modify a Point, which I had made have a property. It's pointless to
do this (initially it will compile, but you'll run into...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |