Value of a Dictionary string[]

C

coder316

Hello
I have a dictionary d <int,string[]> and I am trying to get the value
of a specific string[]
I can iliterate over them with:
foreach(string s in d[1])
{

textBox1.AppendText(s + "\r\n");

}

But I just want d[2][s5] //illistrative puposes only
How do i state the index of an array within a dictionary?
Thanks
 
G

**Group User**

Hello
I have a dictionary d <int,string[]> and I am trying to get the value
of a specific string[]
I can iliterate over them with:
foreach(string s in d[1])
            {

                textBox1.AppendText(s + "\r\n");

            }

But I just want d[2][s5]  //illistrative puposes only
How do i state the index of an array within a dictionary?
Thanks

Sometimes I am sad and hungry
And when I am online
All kind and nice people are available
I am happy to input some into your thread
Because I just drank up some bitter coffee

Things in a dictionary are stored in collections where they are called
via particular objects which will access base class, derived class
whose siblings if accessed will provoke the polymorphic behaviors.
 
K

Konrad Neitzel

Hi!

coder316 said:
I have a dictionary d <int,string[]> and I am trying to get the value
of a specific string[]
I can iliterate over them with:
foreach(string s in d[1])
{

textBox1.AppendText(s + "\r\n");

}

But I just want d[2][s5] //illistrative puposes only
How do i state the index of an array within a dictionary?

Just try (d[2])[s5]. That should work. At least my code fragment was
compiled fine:

Dictionary<int, string[]> stringArrayDictionary = new
Dictionary<int,string[]>();
string singleString = (stringArrayDictionary[2])[0];

(So please try to use names that tells something. d and s5 are not
really nice names for a variable. In my case the name is also not that
good, but the stringArrayDictionary makes no sense for me. But code is
much easier to read if you directly see what a variable contain.)

Konrad
 
A

Arne Vajhøj

I have a dictionary d<int,string[]> and I am trying to get the value
of a specific string[]
I can iliterate over them with:
foreach(string s in d[1])
{

textBox1.AppendText(s + "\r\n");

}

But I just want d[2][s5] //illistrative puposes only
How do i state the index of an array within a dictionary?

Just as you wrote !

Dictionary<int, string[]> d = new Dictionary<int, string[]>();
d.Add(1, new string[] { "A", "B", "C", "D", "E", "F", "G",
"H" });
Console.WriteLine(d[1][5]);

outputs F as expected.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top