Trying to consolidate this...
string[] array = new string[];
array[0] = "Index 0";
array[3] = "Index 3";
array[4] = "index 4";
Into one line...
Example in PHP
$array = array( 0 => "Index 0", 3 => "Index 3", 4 => "Index 4" );
I know I can do this
string[] array = { "string1", "string2", "string3" }
But how would i get the proper indexes in there?
In C programming String is a 1-D array of characters and is defined as an array of characters. But an array of strings in C is a two-dimensional array of character types. Each String is terminated with a null character (\0). It is an application of a 2d array.
All arrays implement IList, and IEnumerable. You can use the foreach statement to iterate through an array.
It sounds like you're really after a Dictionary<int, string>
rather than a traditional C# array:
var dictionary = new Dictionary<int, string>
{
{ 0, "Index 0" },
{ 3, "Index 3" },
{ 4, "Index 4" }
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With