Dvlnblk

I know this should be very simple but I just don't know the correct syntax. How can I create an array of strings, say "ronny", bobby", "ricky","mike" and then access them in the XAML to...say populate a listBox

Thanks, Dvl



Re: Visual C# General Create and Display an Array

DMan1

Dim StringArray() As String = {"ronny", "bobby", "ricky", "mike"}

For Each s As String In StringArray

Me.ListBox1.Items.Add(s)

Next






Re: Visual C# General Create and Display an Array

Dvlnblk

Is that for c# because when I put that in my C# code behind page it has a lot of errors



Re: Visual C# General Create and Display an Array

Dvlnblk

I think I have figured it out, but now how do I add it to a listBox

String[] myNameArray = new string[] { "Ronny", "Bobby", "Ricky", "Mike" };

MessageBox.Show(myNameArray[0]);





Re: Visual C# General Create and Display an Array

DMan1

Dvlnblk wrote:
Is that for c# because when I put that in my C# code behind page it has a lot of errors

LOL...if you want C# you may want to think about posting in the C# forums instead of the VB...But I'm in a good mood so here ya go:

private void button1_Click(object sender, EventArgs e)

{

String[] myNameArray = new string[] { "Ronny", "Bobby", "Ricky", "Mike" };

foreach (String s in myNameArray)

{

this.listBox1.Items.Add(s);

}

}

Moving thread to C# forums






Re: Visual C# General Create and Display an Array

Dvlnblk

So sorry! But wait, are we not in the C# forums


MSDN Forums Visual C# Visual C# General Re: Create and Display an Array

I am confused. Again, sorry if I posted in the wrong place. Thanks for the help, BTW!





Re: Visual C# General Create and Display an Array

DMan1

Yes, we are in the C# forums NOW!!!

As a moderator, I moved the thread from VB to C#






Re: Visual C# General Create and Display an Array

Dvlnblk

Haha! Okay, I got it now. Sorry about being a bit too careless in my choice of forums. Thanks for the help too.