Possible Duplicate:
Set array key as string not int?
I know you can do something like
$array["string"]
in php but can you also do something like this in C# instead of using arrays with numbers?
Possible Duplicate:
Set array key as string not int?
I know you can do something like
$array["string"]
in php but can you also do something like this in C# instead of using arrays with numbers?
Arrays in PHP are in reality more like dictionaries in C#. So yes, you can do this, using a Dictionary<string, YourValueType>
:
var dict = new Dictionary<string, int>();
dict["hello"] = 42;
dict["world"] = 12;
If you want to store key/value pairs, you could probably use a Dictionary: http://msdn.microsoft.com/en-us/library/xfhwa508.aspx
In PHP the "array" class is actually a map, which is a data structure that maps values to keys.
In C# there are a lot of distinct data structure classes. Each with it's own characteristics.
Wikipedia is a good starting point to read about basic data structures in general:
http://en.wikipedia.org/wiki/Data_structure#Common_data_structures
var dictionary = new Dictionary<string, string>();
dictionary["key"] = "value";
and so on