using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication2
{
public interface IReadOnlyList<T>
: IEnumerable<T>, System.Collections.ICollection
{
T this[int Index] { get; }
}
public class MyList<T>: List<T>, IReadOnlyList<T>
{
}
public partial class Form1 : Form
{
MyList<int> list = new MyList<int>();
public Form1()
{
for(int i=0; i<20;++i)
list.Add(i);
InitializeComponent();
}
public IReadOnlyList<int> GetList { get { return list; } }
public ReadOnlyCollection<int> GetList2 { get { return list.AsReadOnly(); } }
private void button1_Click(object sender, EventArgs e)
{
IReadOnlyList<int> ro = this.GetList;
ro.Add(20);
ReadOnlyCollection<int> ro2 = this.GetList2;
ro2.Add(20);
}
}
}