If you want to attach it to a list item (not .Add)

Asked 2 years ago, Updated 2 years ago, 37 views

Syntax question for C#.If you want to add a number (variable converted to string) to each item in the foreach statement about the list box, .Insert does not seem to work.What's wrong?Is there any other good way?(*I would like to attach it to one item, so it is not .Add.)

foreach (string item in names)
{
    NameList.Items.Insert(number);
}

c#

2022-09-30 19:51

1 Answers

This should simply be accessed as an array.

int fruits=10;
int listcount = NameList.Items.Count;
intquotient=fruits/listcount;
for (inti=0;i<listcount;i++)
{
    NameList.Items[i]+=":"+quotient.ToString();
}


2022-09-30 19:51

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.