I asked a question the other day on this subject, but I think I made it too complicated.
In my DataObjects class I have a class called User. Which, to keep things simple, let's say looks like this.
In my DataAccess class I want to return a list of users, so I might have this:Code:public class User { private int _UserID; public int UserID { get { return _UserID; } set { _UserID = value; } } public string UserName { get { return _UserName; } set { _UserName = value; } } }
And, on any .aspx page I can get my list of users by writing this:Code:public List<DataObjects.User> getUsers() { List<DataObjects.Event> myUsersList = new List<DataObjects.Event>(); SqlConnection myConnection = new SqlConnection(connectionString); SqlCommand myCommand = myConnection.CreateCommand(); SqlDataReader dr; myCommand.CommandText = "getUsers"; myCommand.CommandTimeout = 120; myCommand.Connection = myConnection; myCommand.CommandType = CommandType.StoredProcedure; myConnection.Open(); dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection); if (dr.HasRows) { while (dr.Read()) { DataObjects.User myUser = new DataObjects.User(); myUser.UserID = (dr["UserID"] == null) ? 0 : Convert.ToInt32(dr["UserID"].ToString()); myUser.UserName = (dr["UserName"] == null) ? "" : dr["UserName"].ToString(); myUsersList.Add(myUser); } } return myUsersList; }
Which all works fine.Code:DataAccess da = new DataAccess(); List<DataObjects.User> myUsersList = new List<DataObjects.User>(); myUsersList = da.getUsers(); gvUsers.DataSource = myUsersList; gvUsers.DataBind();
So, my question is ... what does the code snippet mean in the context of the Data Objects class? I have a User Object and I can create a list of UserObjects easily enough (as above) ... so what does the code below mean or represent?
I assumed it was effective a sort of shortcut so that, for example, in the DataAccess class instead of creating the List like this ..Code:public class UsersList : List<User> { }
... I thought you might be able to create it (something) like this:Code:List<DataObjects.Event> myUsersList = new List<DataObjects.Event>();
... but all I get are syntax errors. Have I missed something fundamental here?Code:UsersList myUsersList - new List<UsersList>;
Thanks for any help.




Reply With Quote