Thursday, January 8, 2009

ReadOnlyCollectionBase Class

Provides the abstract base class for a strongly typed non-generic read-only collection.This class makes the underlying collection available through the InnerList property.
Since ReadOnlyCollectionBase implements IEnumerable Interface you can iterate through the collection.

//class
using System.Collections;
class ShalvinBlogs : ReadOnlyCollectionBase

{
public void Add(String value)
{
InnerList.Add(value);
}
public string this[int index]

{
get
{
return (string)InnerList[index];
}
}
}

//Forms
ShalvinBlogs sb = new ShalvinBlogs();

private void Form1_Load(object sender, EventArgs e)
{
sb.Add("Shalvinpd.blogspot.com");
sb.Add("DotNetShalvin.blogspot.com");
foreach (string str in sb)
listBox1.Items.Add(str);
}
private void button1_Click(object sender, EventArgs e)

{
textBox1.Text = sb[0];
}

Related Blogs
Generics and Collection Initializer in .Net
Hashtable and DictionaryEntry

No comments:

Post a Comment