c# - Editing an item in a list<T> -


how edit item in list in code below:

list<class1> list = new list<class1>();  int count = 0 , index = -1; foreach (class1 s in list) {     if (s.number == textbox6.text)         index = count; // found match , want edit item @ index     count++; }  list.removeat(index); list.insert(index, new class1(...)); 

after adding item list, can replace writing

list[someindex] = new myclass(); 

you can modify existing item in list writing

list[someindex].someproperty = somevalue; 

edit: can write

var index = list.findindex(c => c.number == sometextbox.text); list[index] = new someclass(...); 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -