I’m wondering if the index of an array can be given a name in C# instead of the default index value. What I’m basically looking for is the C# equivalent of the following PHP code:
$array = array(
"foo" => "some foo value",
"bar" => "some bar value",
);
Cheers.
PHP blends the concept of arrays and the concept of dictionaries (aka hash tables, hash maps, associative arrays) into a single
arraytype.In .NET and most other programming environments, arrays are always indexed numerically. For named indices, use a dictionary instead:
Unlike PHP’s associative arrays, dictionaries in .NET are not sorted. If you need a sorted dictionary (but you probably don’t), .NET provides a sorted dictionary type.