Vipul
Vipul

Reputation: 35

How to update a specific element from List<T> element collections?

I have a list of custom objects List and I would like to update a specific element say 3rd element from top, How would I do that in C#?

Upvotes: 2

Views: 1912

Answers (2)

Adrian Godong
Adrian Godong

Reputation: 8911

Use List<T>.Item property.

Upvotes: 1

Daniel A. White
Daniel A. White

Reputation: 190907

// Updates a property or member of the item
myList[2].myProperty = something;

// Replaces the item in the list
myList[2] = someNewItem;

Upvotes: 8

Related Questions