467,903 Members | 1,840 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,903 developers. It's quick & easy.

List, Dictionary or something else?

I'm pulling records from or database by dates, and there are multiple records
for each part number.

The part numbers are being stored as strings in a List in a custom Employee
class:

List<stringParts = new List<string>();

If a part number is not already in the list, a new entry is created for an
employee that gets credited this part number:

foreach (EmployeeRecord emp in Employee) {
if (emp.Parts.Contains(strPartNum) == false) {
emp.Parts.Add(strPartNum);
emp.TotalParts += 1;
}
}

This seems very efficient to me.

Now, I have been asked to modify my collection to include the Date that this
part number was recorded.

Does anyone know of a good way to do this?

I've considered using a Dictionary entry using a part number as the key and
the data as the value (or vice versa), but I don't know enough about how to
use these Dictionary entries in a way that is not an actual dictionary.

I tried creating a special class to hold a part number and a date, then
adding that to my List, but then there does not seem to be a way to parse the
List to see if a part number has already been added.

I'm working with Visual Studio 2005 (.NET Framework 2.0).

What other techniques are there that I could look into? Are there better
(i.e. faster) techniques? I don't mind writing more code, but I do to go
through the data quickly.
Nov 10 '08 #1
  • viewed: 2924
Share:
2 Replies
First, it seems that the TotalParts property shouldn't be assigned to.
Why not get the count of the parts from the collection exposed by Parts? It
allows someone to set the number of parts which would be out of line with
the items exposed by the Parts collection.

As for your specific problem, I would have the part numbers in a
separate collection, not attached to the part or employee. The date the
part number was entered doesn't seem to fit into the domain of the parts (I
don't know the specific domain, so I can't say), but it almost seems like an
audit trail of some sort, and is generally not exposed as part of the entity
in a business model.

I would keep the collection separately, keyed on the part number.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jp2msft" <jp*****@discussions.microsoft.comwrote in message
news:46**********************************@microsof t.com...
I'm pulling records from or database by dates, and there are multiple
records
for each part number.

The part numbers are being stored as strings in a List in a custom
Employee
class:

List<stringParts = new List<string>();

If a part number is not already in the list, a new entry is created for an
employee that gets credited this part number:

foreach (EmployeeRecord emp in Employee) {
if (emp.Parts.Contains(strPartNum) == false) {
emp.Parts.Add(strPartNum);
emp.TotalParts += 1;
}
}

This seems very efficient to me.

Now, I have been asked to modify my collection to include the Date that
this
part number was recorded.

Does anyone know of a good way to do this?

I've considered using a Dictionary entry using a part number as the key
and
the data as the value (or vice versa), but I don't know enough about how
to
use these Dictionary entries in a way that is not an actual dictionary.

I tried creating a special class to hold a part number and a date, then
adding that to my List, but then there does not seem to be a way to parse
the
List to see if a part number has already been added.

I'm working with Visual Studio 2005 (.NET Framework 2.0).

What other techniques are there that I could look into? Are there better
(i.e. faster) techniques? I don't mind writing more code, but I do to go
through the data quickly.

Nov 10 '08 #2
Thanks for the help.

Now... Where's a good place to get a quick understanding of the difference
between this business model and the others? (I suppose they are application
layer and data layer)

These terms are tossed around from time to time, and I feel like I missed
this chapter.

"Nicholas Paldino [.NET/C# MVP]" wrote:
First, it seems that the TotalParts property shouldn't be assigned to.
Why not get the count of the parts from the collection exposed by Parts? It
allows someone to set the number of parts which would be out of line with
the items exposed by the Parts collection.

As for your specific problem, I would have the part numbers in a
separate collection, not attached to the part or employee. The date the
part number was entered doesn't seem to fit into the domain of the parts (I
don't know the specific domain, so I can't say), but it almost seems like an
audit trail of some sort, and is generally not exposed as part of the entity
in a business model.

I would keep the collection separately, keyed on the part number.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jp2msft" <jp*****@discussions.microsoft.comwrote in message
news:46**********************************@microsof t.com...
I'm pulling records from or database by dates, and there are multiple
records
for each part number.

The part numbers are being stored as strings in a List in a custom
Employee
class:

List<stringParts = new List<string>();

If a part number is not already in the list, a new entry is created for an
employee that gets credited this part number:

foreach (EmployeeRecord emp in Employee) {
if (emp.Parts.Contains(strPartNum) == false) {
emp.Parts.Add(strPartNum);
emp.TotalParts += 1;
}
}

This seems very efficient to me.

Now, I have been asked to modify my collection to include the Date that
this
part number was recorded.

Does anyone know of a good way to do this?

I've considered using a Dictionary entry using a part number as the key
and
the data as the value (or vice versa), but I don't know enough about how
to
use these Dictionary entries in a way that is not an actual dictionary.

I tried creating a special class to hold a part number and a date, then
adding that to my List, but then there does not seem to be a way to parse
the
List to see if a part number has already been added.

I'm working with Visual Studio 2005 (.NET Framework 2.0).

What other techniques are there that I could look into? Are there better
(i.e. faster) techniques? I don't mind writing more code, but I do to go
through the data quickly.


Nov 10 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Bart Nessux | last post: by
10 posts views Thread by Bulba! | last post: by
125 posts views Thread by Raymond Hettinger | last post: by
4 posts views Thread by Travers Naran | last post: by
10 posts views Thread by Ben | last post: by
7 posts views Thread by Sehboo | last post: by
5 posts views Thread by John Cantley | last post: by
2 posts views Thread by Terry Reedy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.