Tutorial by Examples

Using the Constructor A ReadOnlyCollection is created by passing an existing IList object into the constructor: var groceryList = new List<string> { "Apple", "Banana" }; var readOnlyGroceryList = new ReadOnlyCollection<string>(groceryList); Using LINQ Additiona...
A ReadOnlyCollection cannot be edited directly. Instead, the source collection is updated and the ReadOnlyCollection will reflect these changes. This is the key feature of the ReadOnlyCollection. var groceryList = new List<string> { "Apple", "Banana" }; var readOnlyGroc...
If the source collection is of a type that is not immutable, elements accessed through a ReadOnlyCollection can be modified. public class Item { public string Name { get; set; } public decimal Price { get; set; } } public static void FillOrder() { // An order is generated ...

Page 1 of 1