E
Ethan Strauss
Hi,
I have just started using Generic Collections for .Net 2.0 and so far
they are working very nicely for me. But, I do have a couple of questions.
If I have a Generic collection which has a type which is a reference type,
is there a way to get Collection.ContainsKey(RefKey) and Collection[RefKey]
to work with different instances of equal keys?
For example, I have defined a class of "codon" and I have made a dictionary
private System.Collections.Generic.Dictionary<Codon, Double> CodonUsage;
I have two instances of CodonUsage and want to write codon similar to:
if (CodonUsageInstance1[ThisCodon] == CodonUsageInstance2[ThisCodon])
{
Do Stuff;
}
but this doesn't work. I am pretty sure that it is because the two different
instances of Codon Usage were populated with different instances of Codons
and thus they don't contain entries for arbitrary Codons even if they do
contain entries for Codons which are identical. My definition for Codon does
have an override of equals, so that different instances will evaluate to
equals correctly. I have similar issues with .ContainsKey.
Any help would be appreciated.
Thanks!
Ethan
Ethan Strauss Ph.D.
Bioinformatics Scientist
Promega Corporation
2800 Woods Hollow Rd.
Madison, WI 53711
608-274-4330
800-356-9526
(e-mail address removed)
I have just started using Generic Collections for .Net 2.0 and so far
they are working very nicely for me. But, I do have a couple of questions.
If I have a Generic collection which has a type which is a reference type,
is there a way to get Collection.ContainsKey(RefKey) and Collection[RefKey]
to work with different instances of equal keys?
For example, I have defined a class of "codon" and I have made a dictionary
private System.Collections.Generic.Dictionary<Codon, Double> CodonUsage;
I have two instances of CodonUsage and want to write codon similar to:
if (CodonUsageInstance1[ThisCodon] == CodonUsageInstance2[ThisCodon])
{
Do Stuff;
}
but this doesn't work. I am pretty sure that it is because the two different
instances of Codon Usage were populated with different instances of Codons
and thus they don't contain entries for arbitrary Codons even if they do
contain entries for Codons which are identical. My definition for Codon does
have an override of equals, so that different instances will evaluate to
equals correctly. I have similar issues with .ContainsKey.
Any help would be appreciated.
Thanks!
Ethan
Ethan Strauss Ph.D.
Bioinformatics Scientist
Promega Corporation
2800 Woods Hollow Rd.
Madison, WI 53711
608-274-4330
800-356-9526
(e-mail address removed)