SLI
SLI

Reputation: 753

C# Get Data from array in same way like i can in php

how can get data from array in same way like i can in php?

$arr = array(
    '123' => 'abc',
    '456' => 'def'
);
echo $arr['123']; // abc

How can i do same with array's at C#?

Upvotes: 2

Views: 71

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460168

That looks like a dictionary:

Dictionary<int, string> dict = new Dictionary<int, string>
{
    {123, "abc"}, {456, "def"}
};
Console.WriteLine(dict[123]);  // abc

Upvotes: 5

Related Questions