Search code examples
c#listviewitem

c# string array reference


I'm new to c# but struggling with some fairly basic assignments.

This works:

ListViewItem item = new ListViewItem(new[] { "1", "2", "3", "4" });

This Does not:

string[] rrr = new string[4]{ "1", "2", "3", "4" };
ListViewItem item = new ListViewItem(new[] rrr);

My Final goal is:

for (int i=0; i<10; i++)
{
    rrr[i] = "SomeText";
}
ListViewItem item = new ListViewItem(new[] rrr);

Apologies for the basic question, I've not been able to find the right keywords to get a solution. I'm more used to VBA which allows me to get away with anything.....

Thanks


Solution

  • You should do only this

    string[] rrr = new string[4]{ "1", "2", "3", "4" };
    ListViewItem item = new ListViewItem(rrr);
    

    so:

    for (int i=0; i<10; i++)
    {
        rrr[i] = "SomeText";
    }
    ListViewItem item = new ListViewItem(rrr);