2

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#?

3
  • What would you like to have as result? Commented Jul 7, 2016 at 13:53
  • I just want to access specific data at array by it's name without searching in array each time when i need it. Commented Jul 7, 2016 at 13:55
  • I think what your looking for is a Dictionary<int, string> Commented Jul 7, 2016 at 14:03

1 Answer 1

5

That looks like a dictionary:

Dictionary<int, string> dict = new Dictionary<int, string>
{
    {123, "abc"}, {456, "def"}
};
Console.WriteLine(dict[123]);  // abc
Sign up to request clarification or add additional context in comments.

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.