Need a bit of help, I'd like to add a custom type to a dictionary or key/value pair. But - not coming right - and not an application developer.
Basically, I want a list/dictionary/array/whatever to store a simple collection of keys (always int) - and values (could be a single string, or a combination of strings, or a combination of strings and integers.
I'd then like to be able to search this collection as fast as possible by either the key - or the value collection.
I currently have the following (simplified), but would like to extend it to allow multiple values:
(ignore the layout as some of it is done in different sections of code)
My ideal outcome would be to allow for
List<KeyValuePair<int, string>> ListCache;
to have a collection of Values that are also searchable, e.g.
List<KeyValuePair<int, [int, string]>> ListCache;
Basically, I want a list/dictionary/array/whatever to store a simple collection of keys (always int) - and values (could be a single string, or a combination of strings, or a combination of strings and integers.
I'd then like to be able to search this collection as fast as possible by either the key - or the value collection.
I currently have the following (simplified), but would like to extend it to allow multiple values:
(ignore the layout as some of it is done in different sections of code)
Code:
List<KeyValuePair<int, string>> ListCache;
ListCache = new List<KeyValuePair<int, string>>();
<somewhere else in a class>
ListCache<int, string> record_found = ListCache.SingleOrDefault(x => x.Value == "incoming search term");
int outputKey = record_found .Key;
// if record not in list
if (outputKey == 0)
{
// do some db stuff
ListCache.Add(new KeyValuePair<int, string>(newKey, "incoming search term"));
outputKey = newKey;
}
return outputKey;
My ideal outcome would be to allow for
List<KeyValuePair<int, string>> ListCache;
to have a collection of Values that are also searchable, e.g.
List<KeyValuePair<int, [int, string]>> ListCache;