TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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
Reply
Answers (
3
)
Understanding datasets in c#/visual studio 2005
Method return class list, no idea how to use it effectively