I had to change my lines of code. I used to have something like this
List<string> mySTring = new List<string>();
mySTring.add("one");
mySTring.add("two");
However, on one of my pages I have a drop-down list that does not require a “two” field, so instead of writing duplicate code, all I did was
myString.remove("two");
Now I need to change my list to List<SelectListItem> myList = new List<SelectListItem>();
So now it looks like this for me:
List<SelectListItem> myList = new List<SelectListItem>()
{
new SelectListItem() { Text = "one", Value = "one"},
new SelectListItem() { Text = "two", Value = "two"},
};
So, how to remove the selectListItem element containing two? I know that maybe I can use delete by index. But I could add to the list in the future, so I don’t want to start searching and change it if the index changes.
thanks
source
share