❔ Using lists interchangeably
Hello, I have a situation where all of my code is the same aside from which lists are used in a for statement. How can I determine which list to use and swap it with a single variable?
Example:
(Before)
switch (ListType)
{
case 0:
for (int x = 0; x < ListA.Count; x++)
{
}
case 1:
for (int x = 0; x < ListB.Count; x++)
{
}
case 2:
for (int x = 0; x < ListC.Count; x++)
{
}
}
(After)
for (int x = 0; x < SelectedList.Count; x++)
{
}
(all lists are the same length)
5 Replies
Need more details
are all the lists the same type
what is the logic for picking a list
all of the lists are the same type(string), the logic for picking a list is the selected index of a combobox(so an int)
if I make a list of lists out of ListA, ListB, and ListC, will they be references to those lists or copied?
if they would be references that solves my problem, i dont want them copied as they are 20000+ items each
@Furyion they won't be copied.
ok good, problem solved then, thanks
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.