473,394 Members | 1,944 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,394 software developers and data experts.

generic data structure question

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
7 2004
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

49
by: Steven Bethard | last post by:
I promised I'd put together a PEP for a 'generic object' data type for Python 2.5 that allows one to replace __getitem__ style access with dotted-attribute style access (without declaring another...
17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
1
by: Ben | last post by:
Due to my unfamiliarity with schemas, I am unable to figure out how to accomplish the same type of processing that I have currently working under a dtd. We have a pre-defined generic message...
1
by: Stewart Rogers | last post by:
Hi all, I have been working on an ASP.NET application that is a kind of wizard ( a list of sequential pages ). We built that application for the CLIENT-A and it worked fine. After six months...
5
by: Bob Weiner | last post by:
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:...
6
by: Charles Law | last post by:
I want to do something like this: obj = CType(value, Value.Type) Well, not exactly, but I think that captures the essence. I realise it won't work as I have written it, and it looks a bit like...
3
by: markww | last post by:
Hi, I have a wrapper around some 3rd party database library function. The pseudo code looks like the following - it is meant to open a table in a database, extract values from a table, then copy...
1
by: Miesha.James | last post by:
Hello, I'm trying to rewrite visual c++ code into visual c++ .NET code and I've run across a problem with storing objects into a list. Here;s an example of the code I have: ref struct...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
11
by: Bob Altman | last post by:
Hi all, I want to write a generic class that does this: Public Class X (Of T) Public Sub Method(param As T) dim x as T = param >3 End Sub End Class
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.