Re: Duplicate Key Alternative for Generic Dictionary

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




To me it sounds like you're trying to avoid creating a Department
object even though that is exactly what you need. This code would be
much easier to read and understand and manage and debug and on and on
and on..

var d1 = new Department();
var d2 = new Department();
var d3 = new Department();

var departments = new Dictionary<Guid, Department>();

departments.Add(d1.Guid, d1);
departments.Add(d2.Guid, d2);
departments.Add(d3.Guid, d3);

d1.Users.Add(new User());
d1.Users.Add(new User());
d1.Users.Add(new User());

d2.Users.Add(new User());
d2.Users.Add(new User());
d2.Users.Add(new User());

d3.Users.Add(new User());
d3.Users.Add(new User());
d3.Users.Add(new User());

3 departments in a dictionary, each with 3 users (employees). Not
fully working code (need class definitions), but hopefully this is
enough to explain.

HTH,

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.


On Tue, 18 Dec 2007 16:23:16 -0500, "sloan" <sloan@xxxxxxxxx> wrote:


I guess pretend I have 3 departments, and 3 employees in each one.

That is the reason. I'm either going to have to wrap my own custom object
collection, or try and piggy back.


Guid dept1 = new Guid("00000000-0000-0000-0000-000000000001");
Guid dept2 = new Guid("00000000-0000-0000-0000-000000000002");
Guid dept3 = new Guid("00000000-0000-0000-0000-000000000003");

test.Add(dept1 , Guid.NewGuid());

test.Add(dept1 , Guid.NewGuid());
test.Add(dept1 , Guid.NewGuid());

test.Add(dept2 , Guid.NewGuid());
test.Add(dept2 , Guid.NewGuid());
test.Add(dept2 , Guid.NewGuid());

test.Add(dept3 , Guid.NewGuid());
test.Add(dept3 , Guid.NewGuid());
test.Add(dept3 , Guid.NewGuid());


.



Relevant Pages

  • Classes / Functions / Autonomy
    ... I do get a bit wordy at times. ... var $WhyUseVars; ... Of course, then I come up with the thought, that I might want to use the second function outside of the first function, but I've written the ... Im not sure what the best way is, I know I just want to avoid needless repetition, keep things simple, and avoid the situation where Im passing the same information in chained function calls. ...
    (comp.lang.php)
  • Re: Attach a class method to event handler
    ... How do I avoid the closure of my object reference? ... var target = document.getElementById; ...
    (comp.lang.javascript)
  • Re: pointer syntax
    ... Best practice is to avoid the issue altogether. ... var SearchResult; ... pointers and not with var parameters: you can pass null as the pointer. ... the receiving code has to check for this every ...
    (comp.lang.pascal.delphi.misc)
  • had Latent-Time disabled. It had a destination block set for
    ... its var ... Remailer operators vary in their administrative techniques. ... Some avoid ...
    (sci.crypt)
  • Re: Is there a way to use filtering in E4X with hyphenated XML elements?
    ... var phoneList = ... This assumes that the COMPANY-NAME element node is the first sibling. ...
    (comp.lang.javascript)