c# - Collection with two keys -


In the solution I have worked in this question => (see editing in the bottom of the question), I need it

Therefore, I need to get a method like type 1 and type 2.

Answer this question => It is recommended to use one dictionary of dictionaries like it is what I am doing.

But I do not like it. It shows what is meant to represent the collection, does not flow logically. I should also do something to get the value:

  if (! _Types.ContainsKey (s.GetType ())) {type1Cache = new dictionary & lt; Type, conversion cache & gt; (); _Types.Add (s.GetType (), type1Cache); } And {type1Cache = _Types [s.GetType ()]; } If (! Type1Cache.ContainsKey (value.GetType ())) {// We have changed this type earlier, then create a new conversion type - cachecache = new conversion cache (s.GetType (), value.GetType ()); // Add to the cache type 1 cache. Add (value.GetType (), type2Cache); } And {type2Cache = type1Cache [value.GetType ()]; }  

Which is slightly curved.

I just want to do something

  if (! _Types.ContainsKey (S.GetType (), value.GetType ())) {cache = new ConversionCache .GetType), value.GetType ()); _Types.Add (s.GetType (), value.GetType (), cache); } And {cache = _Types [s.GetType (), value. GetType ()]; }  

The string value of a solution type must be added. Something like this:

  if (! _Types.ContainsKey (s.GetType) toString () + ":" + value.GetType (). ToString ())) {cache = new ConversionCache () S.GetType (), Price GetType ()); _Types.Add (s.GetType () .ostring () + ":" + value.GetType (.) ToString (), cache); } And {cache = _Types [s.GetType (). Ostring () + ":" + value.GetType (). ToString ()]; }  

I know that this will work in this example because one type is between one type and its string representation

but it stinks very much , And will not work in other situations.

Is there a better way to do this?

The way you're doing it is okay. If you need a better "smocking" system, then you need an auxiliary function that takes two input (or type) and returns a unique string. Then the implementation details of the key (hidden in this case by adding them to "separator") is hidden.

There is a little more engineering for me. I do not believe that there is a big chance for this opportunity, so that you have to change the way of this major generation and you are not trying to create a normal class. Obviously you have to do this with the normal range.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -