dobby

dobby

  • NA
  • 53
  • 0

Help, how do i return a list of a class from a method.

Jul 8 2008 1:45 PM
hi, im fairly new to c# and havent grasped al the concepts just yet:
i got stuck while making a method, which i want to return List which is declares inside the method, i just cant get it to work;

heres what im currently doing:

    class T{public String s; public int i;}
    class Main
    {
        public List<T> makeList()
        {
            List<T> temp = new List<T>();
            temp.AddRange(new T());
            temp[0].s = "hello";
            temp[0].i = 1234;
            return temp<T>;
        }   
    }


Error    1    The best overloaded method match for 'System.Collections.Generic.List<WindowsFormsApplication1.T>.AddRange(System.Collections.Generic.IEnumerable<WindowsFormsApplication1.T>)'
Error    2    Argument '1': cannot convert from 'WindowsFormsApplication1.T' to 'System.Collections.Generic.IEnumerable<WindowsFormsApplication1.T>'

obviously i dont need to use list in this example, however i have a project which does i just want to know how to make the method work

many thanks

Answers (3)