When I want to make a value type read-only outside of my class I do this:
public class myClassInt
{
private int m_i;
public int i {
get { ret
public static IEnumerable AsReallyReadOnly(this IEnumerable source)
{
foreach (T t in source) yield return t;
}
if I add to Earwicker's example
...
IEnumerable f = a.AsReallyReadOnly();
IList g = f.AsWritable(); // finally can't get around it
g.Add(8);
Debug.Assert(a.Count == 78);
I get InvalidOperationException: Sequence contains no matching element
.