Click here to Skip to main content
16,006,001 members
Home / Discussions / C#
   

C#

 
AnswerRe: asp controls in web application Pin
Calin Tatar28-Feb-09 0:34
Calin Tatar28-Feb-09 0:34 
QuestionBHO and cookies ? Pin
tsahiB27-Feb-09 21:24
tsahiB27-Feb-09 21:24 
QuestionLooking for tips & tricks Pin
E_Gold27-Feb-09 20:08
E_Gold27-Feb-09 20:08 
AnswerRe: Looking for tips & tricks Pin
Abhijit Jana27-Feb-09 20:42
professionalAbhijit Jana27-Feb-09 20:42 
GeneralRe: Looking for tips & tricks Pin
E_Gold27-Feb-09 21:14
E_Gold27-Feb-09 21:14 
AnswerRe: Looking for tips & tricks Pin
Eddy Vluggen27-Feb-09 22:31
professionalEddy Vluggen27-Feb-09 22:31 
QuestionProblem with Generic Collection and Interface Pin
_ro_bb_o27-Feb-09 19:06
_ro_bb_o27-Feb-09 19:06 
AnswerRe: Problem with Generic Collection and Interface Pin
DaveyM6928-Feb-09 2:40
professionalDaveyM6928-Feb-09 2:40 
Not sure why you need to do this. Making the ClientCollection class derive from List<Client> or List<ItemInterface> should be sufficient. Creating a n interface that derives from IList<ItemInterface> is just going to create a wrapper around an internal list of the same.

Anyway, this is how you do it. I've use IItem and ICollection for the interface names.
Client clientA = new Client(1);
Client clientB = new Client(2);
Client clientC = new Client(3);
ClientCollection clients = new ClientCollection();
clients.Add(clientA);
clients.Add(clientB);
clients.Add(clientC);
foreach(IItem item in clients)
{
    Console.WriteLine(item.ID);
}
/* alternative
foreach(Client client in clients)
{
    Console.WriteLine(client.ID);
}*/
public interface IItem
{
    Int32 ID { get; set; }
}
public interface ICollection : IList<IItem>
{ }
public class Client : IItem
{
    public Client(Int32 id)
    {
        ID = id;
    }

    #region IItem Members

    public int ID
    {
        get;
        set;
    }

    #endregion
}
public class ClientCollection : ICollection
{
    private List<IItem> list;

    public ClientCollection()
    {
        list = new List<IItem>();
    }

    #region IList<IItem> Members

    public int IndexOf(IItem item)
    {
        return list.IndexOf(item);
    }

    public void Insert(int index, IItem item)
    {
        list.Insert(index, item);
    }

    public void RemoveAt(int index)
    {
        list.RemoveAt(index);
    }

    public IItem this[int index]
    {
        get { return list[index]; }
        set { list[index] = value; }
    }

    #endregion

    #region ICollection<IItem> Members

    public void Add(IItem item)
    {
        list.Add(item);
    }

    public void Clear()
    {
        list.Clear();
    }

    public bool Contains(IItem item)
    {
        return list.Contains(item);
    }

    public void CopyTo(IItem[] array, int arrayIndex)
    {
        list.CopyTo(array, arrayIndex);
    }

    public int Count
    {
        get { return list.Count; }
    }

    public bool IsReadOnly
    {
        get { return false; }
    }

    public bool Remove(IItem item)
    {
        return list.Remove(item);
    }

    #endregion

    #region IEnumerable<IItem> Members

    public IEnumerator<IItem> GetEnumerator()
    {
        return list.GetEnumerator();
    }

    #endregion

    #region IEnumerable Members

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }

    #endregion
}


Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

QuestionReading a Packet assistance Pin
Andrew Timmins27-Feb-09 18:46
Andrew Timmins27-Feb-09 18:46 
AnswerRe: Reading a Packet assistance Pin
Jimmanuel28-Feb-09 1:43
Jimmanuel28-Feb-09 1:43 
QuestionTo Create Crystal Reports With Dynamic Values Pin
aashish.saalvi27-Feb-09 18:46
aashish.saalvi27-Feb-09 18:46 
QuestionC# drag and drop from Treeview to Listview Pin
AlCsharp27-Feb-09 18:01
AlCsharp27-Feb-09 18:01 
AnswerRe: C# drag and drop from Treeview to Listview Pin
Calin Tatar28-Feb-09 1:02
Calin Tatar28-Feb-09 1:02 
QuestionAny good .net obfuscator ? Pin
Kim061827-Feb-09 15:11
Kim061827-Feb-09 15:11 
AnswerRe: Any good .net obfuscator ? Pin
Eddy Vluggen27-Feb-09 23:05
professionalEddy Vluggen27-Feb-09 23:05 
Questionthe problem of set the default page for html help maker (.chm) Pin
Seraph_summer27-Feb-09 10:43
Seraph_summer27-Feb-09 10:43 
QuestionDirectory of the App file ? Pin
Mohammad Dayyan27-Feb-09 10:01
Mohammad Dayyan27-Feb-09 10:01 
AnswerRe: Directory of the App file ? Pin
Calin Tatar27-Feb-09 10:02
Calin Tatar27-Feb-09 10:02 
GeneralRe: Directory of the App file ? Pin
Mohammad Dayyan27-Feb-09 10:05
Mohammad Dayyan27-Feb-09 10:05 
QuestionUsb control channel and buzzer Pin
thomaxz.tc27-Feb-09 8:52
thomaxz.tc27-Feb-09 8:52 
AnswerRe: Usb control channel and buzzer Pin
Curtis Schlak.27-Feb-09 11:43
Curtis Schlak.27-Feb-09 11:43 
GeneralRe: Usb control channel and buzzer Pin
thomaxz.tc28-Feb-09 4:09
thomaxz.tc28-Feb-09 4:09 
QuestionProblem In Middle Tire Pin
naim khan27-Feb-09 8:19
naim khan27-Feb-09 8:19 
AnswerRe: Problem In Middle Tire Pin
Colin Angus Mackay27-Feb-09 10:19
Colin Angus Mackay27-Feb-09 10:19 
GeneralRe: Problem In Middle Tire Pin
Sava Savanovic27-Feb-09 22:47
Sava Savanovic27-Feb-09 22:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.