3

I have a string array:

String[] array1 = new String[10];

Is there anyway I can use keys which are nto numbers?

array["keyhere"] instead of array1[1]

anyone know how?

3 Answers 3

7

Use System.Collections.Generic.Dictionary<TKey, TValue>.

For example:

Dictionary<string, string> myDictionary = new Dictionary<string, string>();

myDictionary.Add("key", "value");

string foo = myDictionary["key"];

Dictionary<TKey, TValue> has some methods that you might find useful, such as ContainsKey().

Sign up to request clarification or add additional context in comments.

Comments

1

Use a dictionary

Dictionary<String,Object> phpArray = new Dictionary<String,Object>();
phpArray.Add("keyhere",1);
MessageBox.Show(phpArray["keyhere"]);

Comments

0

PHP arrays are called associative arrays. You can use either a Dictionary or HashMap to implement the same thing in C#.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.