Suppose we have a List of integers that we want to pass to a method Reader:
class Example {
public void Run() {
// Add more data to the list
lst.Add(2);
lst.Add(3);
/*
how to pass lst to Reader() here
as read-only ?
*/
}
//.... more code
void Reader( ICollection<int> coll ) {
// some code
}
List<int> lst = new List<int>{ 1 };
}
While passing lst to Reader from Run, how can we enforce that the list is not modifiable inside method Reader?