Home > DeveloperSection > Forums > generic list class in c#
Royce Roy
Royce Roy

Total Post:149

Posted on    January-25-2014 1:27 AM

 C# C# 

 1 Reply(s)
 1214  View(s)
Rate this:

I'm currently making my own very basic generic list class (to get a better understanding on how the predefined ones work). Only problem I have is that I can't reach the elements inside the array as you normally do in say using "System.Collections.Generic.List".

GenericList<type> list = new GenericList<type>();


This works fine, but when trying to access "whatever" I want to be able to write :


But that obviously doesn't work since I'm clearly missing something in the code, what is it I need to add to my otherwise fully working generic class ?

Pravesh Singh

Total Post:412

Posted on    January-25-2014 1:48 AM

Hi Royce,

I think all you need to do is implement IList<T> , to get all the basic functionality

  public interface IList<T> 


    int IndexOf(T item);

    void Insert(int index, T item);

    void RemoveAt(int index);

    T this[int index] { get; set; }


Don't want to miss updates? Please click the below button!

Follow MindStick