c# - Need a data structure that allows duplicate key -
i have data in rows looks this:
(car, color, age)
for example:
ford,red,4
toyota,green,3
ford,blue,2
i need loop on these data rows , perform validation before submitting stored procedure. in case, if there more 1 car of same type need ensure colors different. example above permitted, example not:
ford,red,4
toyota,green,3
ford,red,2
how do in c#. have tried using dictionary, not allow duplicate keys. list not seem correct option either? can offer direction? thanks.
you don't have duplicate keys, have key made of 2 values (a composite key), values car , color. need object represents car/color pair, , has equality implemented based on 2 values.
this means don't need different data structure, dictionary
fine, need come appropriate type use key dictionary. neither car nor color alone key accomplishes want.
you write own; class 2 properties , appropriate equals/gethashcode
overrides, , if use in multiple places in application or sufficiently large scope, should that. if you're using in limited , localized scope, can use tuple<car, color>
dictionary key.
Comments
Post a Comment