By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,712 Members | 1,285 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,712 IT Pros & Developers. It's quick & easy.

generic data structure question

P: n/a
I'm new to C#.

What is the best (in terms of programmability and use) data structure to use
to maintain an array of information with containing 3 fields of differing
types. For instance:
string name
int age
bool gender

If I created an array of structs would I be able to retrieve an age for a
given name without writing a search routine? Can I use the Array.IndexOf
method to retrieve the correct record?

Would a Hashtable/Dictionary be more efficient? Do I need to create my own
class? With VB6 I've used a recordset but bringing in ADO seems like
overkill.

Not vital but I would like to put the perenial problem to rest.

thanks,
bob
Nov 16 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
It sounds like a database table - you have 3 fields, and multiple records.
Try using a datatable.

"Bob Weiner" <bo*@engr.uconn.edu> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
I'm new to C#.

What is the best (in terms of programmability and use) data structure to use to maintain an array of information with containing 3 fields of differing
types. For instance:
string name
int age
bool gender

If I created an array of structs would I be able to retrieve an age for a
given name without writing a search routine? Can I use the Array.IndexOf
method to retrieve the correct record?

Would a Hashtable/Dictionary be more efficient? Do I need to create my own class? With VB6 I've used a recordset but bringing in ADO seems like
overkill.

Not vital but I would like to put the perenial problem to rest.

thanks,
bob

Nov 16 '05 #2

P: n/a
It depends on what you are doing with it. If it's for a database, a
datatable is a good choice (as mentioned). If it has nothing to do with a
database, then perhaps you don't want to consider that.

Array.IndexOf will work if you override Equals. You can do this on a class,
but it's not recommended.

Without knowing what your goal is, I don't think I'll be much help putting
this "to rest".

-mike
MVP

"Bob Weiner" <bo*@engr.uconn.edu> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
I'm new to C#.

What is the best (in terms of programmability and use) data structure to
use
to maintain an array of information with containing 3 fields of differing
types. For instance:
string name
int age
bool gender

If I created an array of structs would I be able to retrieve an age for a
given name without writing a search routine? Can I use the Array.IndexOf
method to retrieve the correct record?

Would a Hashtable/Dictionary be more efficient? Do I need to create my
own
class? With VB6 I've used a recordset but bringing in ADO seems like
overkill.

Not vital but I would like to put the perenial problem to rest.

thanks,
bob


Nov 16 '05 #3

P: n/a
Thanks for the replies.

I run across this in many question in many applications. Here is a more
concrete example, and the one the prompted me to ask the question. Although
there are lots of ways to get the job done (and in fact the job is not being
slowed down by this question), I really want to know what the best "software
engineering" approach is.

I am creating exchange mailboxes in a test domain to emulate our faculty,
staff, grads, and undergrads. Each have different quotas. So a read a
config file into a sealed, static (whatever it is) class that contains a
section like:

Faculty 80000 100000
Staff 65000 100000
Grad 25000 30000
Undergrad 7000 10000

From one class I have
myUser = new User(joe, test, faculty)

then:

public class User {
// Constructor
public User (string first, string last, string status) {
if (Config.isStatus(status)) // check for a valid
argument
myStatus = status;
}
// Property
public long mDBOverQuotaLimit {
get { return Config.hardLimit(status); }
}
}

How should I store the data in Config so that it is easy to get to? It
seems like there should be a pre-built class designed for this.

I will look at the datatable if that is the best method.
bob

"Bob Weiner" <bo*@engr.uconn.edu> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
I'm new to C#.

What is the best (in terms of programmability and use) data structure to use to maintain an array of information with containing 3 fields of differing
types. For instance:
string name
int age
bool gender

If I created an array of structs would I be able to retrieve an age for a
given name without writing a search routine? Can I use the Array.IndexOf
method to retrieve the correct record?

Would a Hashtable/Dictionary be more efficient? Do I need to create my own class? With VB6 I've used a recordset but bringing in ADO seems like
overkill.

Not vital but I would like to put the perenial problem to rest.

thanks,
bob

Nov 16 '05 #4

P: n/a
Storing the config settings? You most likely want a strongly
typed object that stores your data, say QuotaGroup that stores
the group name, and the quota values. Config can index these
into a hashtable which would allow quick and easy look-up.

For flexibility you can use a case insensitive hashtable.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Bob Weiner" <bo*@engr.uconn.edu> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Thanks for the replies.

I run across this in many question in many applications. Here is a more
concrete example, and the one the prompted me to ask the question. Although
there are lots of ways to get the job done (and in fact the job is not being
slowed down by this question), I really want to know what the best "software
engineering" approach is.

I am creating exchange mailboxes in a test domain to emulate our faculty,
staff, grads, and undergrads. Each have different quotas. So a read a
config file into a sealed, static (whatever it is) class that contains a
section like:

Faculty 80000 100000
Staff 65000 100000
Grad 25000 30000
Undergrad 7000 10000

From one class I have
myUser = new User(joe, test, faculty)

then:

public class User {
// Constructor
public User (string first, string last, string status) {
if (Config.isStatus(status)) // check for a valid
argument
myStatus = status;
}
// Property
public long mDBOverQuotaLimit {
get { return Config.hardLimit(status); }
}
}

How should I store the data in Config so that it is easy to get to? It
seems like there should be a pre-built class designed for this.

I will look at the datatable if that is the best method.
bob

"Bob Weiner" <bo*@engr.uconn.edu> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
I'm new to C#.

What is the best (in terms of programmability and use) data structure to

use
to maintain an array of information with containing 3 fields of differing
types. For instance:
string name
int age
bool gender

If I created an array of structs would I be able to retrieve an age for a
given name without writing a search routine? Can I use the Array.IndexOf
method to retrieve the correct record?

Would a Hashtable/Dictionary be more efficient? Do I need to create my

own
class? With VB6 I've used a recordset but bringing in ADO seems like
overkill.

Not vital but I would like to put the perenial problem to rest.

thanks,
bob


Nov 16 '05 #5

P: n/a
Hi Bob,

Based on my understanding, you need to store your data in a config file and
manipulate it with .Net.

I think you should use DataSet and DataTable as your .Net memory storage.
For your config file, you may use Xml format, then you can easily leverage
DataSet.WriteXml method and DataSet.ReadXml method to export and import
data with your Xml config file.

This should be very flexible. DataSet and DataTable also gives you rich
ability to manipulate with the DataBase.

==============================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #6

P: n/a
Thanks for all the replies.

I will certainly look into the ado classes and the dataset and datatable in
particular. I was delaying getting into ado because I don't currently have
database application needs. I guess ado is useful for more than just
database work, though.

thanks again,
bob

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:fh**************@cpmsftngxa06.phx.gbl...
Hi Bob,

Based on my understanding, you need to store your data in a config file and manipulate it with .Net.

I think you should use DataSet and DataTable as your .Net memory storage.
For your config file, you may use Xml format, then you can easily leverage
DataSet.WriteXml method and DataSet.ReadXml method to export and import
data with your Xml config file.

This should be very flexible. DataSet and DataTable also gives you rich
ability to manipulate with the DataBase.

==============================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #7

P: n/a
Hi Bob,

Thanks very much for your feedback.

Yes, ADO.net has exposed rich function for us, it gives we flexible
opputinity to operate data. ADO.net integrates well with Xml or other
in-memory data processing.

Also, ADO.net gives us a good model of connection-less data handling.

Anyway, I recommand you to touch some of the function of ADO.net(especially
DataSet, DataTable and DataBinding feature), I think it should help you a
lot.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.