0

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

5
  • 11
    What do you expect new[] rrr to do? I suspect you just want new ListViewItem(rrr) Commented May 13, 2014 at 10:09
  • VBA allows you to write and run anything. It does not stop the code from not working. Commented May 13, 2014 at 10:10
  • try this new ListViewItem(rrr); Commented May 13, 2014 at 10:10
  • I actually suspect he wants new ListViewItem(Enumerable.Range(1, i).ToArray()) or new ListViewItem(Enumerable.Repeat("SomeText", i).ToArray()) Commented May 13, 2014 at 10:12
  • Welcome on StackOverflow. You could have mentioned that this doesn't compile and which line which does not compile. Commented May 13, 2014 at 10:12

2 Answers 2

3

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the quick answer and again, sorry for the basic question.
2

Instead of ListViewItem item = new ListViewItem(new[] rrr); use ListViewItem item = new ListViewItem(rrr);

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.