generic data structure question

  • Thread starter Thread starter Bob Weiner
  • Start date Start date
B

Bob Weiner

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
 
It sounds like a database table - you have 3 fields, and multiple records.
Try using a datatable.
 
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
 
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
 
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.
 
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.
 
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
 
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.
 

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

Back
Top