I need to write a simple class.
I need 2 methods:
Vector property = new Vector();
property.add("key", "value"); //set value of key
property.get("key"); //return value of key
Does CSharp have a class like that?
I’m trying write my own class
string[] keys;
public void add(string key, string value)
{
this.keys[key] = value;
}
but string can not be index of array(but must).
Any ideas?
Thanks.
You may use
Dictionary<TKey,TValue>to do this. You may also defineVectoras a class ofDictionaryif you would like to useVectoras aDictionaryExample
This will create a new class
Vectorwhich implementsDictionaryso that you’ll be able to useVectoras aDictionary.Notice: The
Dictionary<TKey, TValue>is a generic class providing a mapping from a set of keys to a set of values. Each addition to the dictionary consists of a value and its associated key. Retrieving a value by using its key is very fast because theDictionary<TKey, TValue>class is implemented as a hash table.Thanks,
I hope you find this helpful 🙂