Hi, I am new to C # and have studied it. Actually I think that I am using it, there are some things that I'm not sure about, but I will try to research them before asking. However, I can not find the collection. I came from the VB.NET database, and earlier I used collections of another class to store my properties instead of wading through datatable. My previous code was something like the following
Public class UserDetails Public Property Username() As String Get Return sUsername End Get Set(ByVal value As String) sUsername = value End Set End Property Public Property Forename() As String Get Return sForename End Get Set(ByVal value As String) sForename = value End Set End Property Public Property Surname() As String Get Return sSurname End Get Set(ByVal value As String) sSurname = value End Set End Property End Class
you get an idea, a class with properties for some reason (this is easy in C # and somthing, which I managed to do).
public string Username { get { return sUsername; } set { sUsername = value; } } public string Forename { get { return sForename; } set { sForename = value; } } public string Surname { get { return sSurname; } set { sSurname = value; } }
Then I have another class and create an object for this class and save each object in the collection as shown below:
clUserDetails = New Collection Dim objUserDetails as new UserDetails objUserDetails.Username = "SomeonesUsername" objUserDetails.Forename = "SomeonesForename" objUserDetails.Surname = "SomeonesSurname" clUserDetails.Add(objUserDetails)
and the class also has a function that returns a collection
Public Function Items() As Collection Return clUserDetails End Function
Now I get this by scrolling through each object and assigning the object to get properties or doing the following
objUsers.Items(1)
Now in C #, I tried using List <>, since I cannot find the collection object. I assume this is a VB thing, so I need help on how to do this in C #.
I tried the following
private List <UserDetails> clUserDetails; UserDetails objUserDetails = new UserDetails(); objUserDetails.Username = "Username"; objUserDetails.Forename = "Forename"; objUserDetails.Surname = "Surname"; clUserDetails.Add(objUserDetails);
but I was fixated on how to get the only object of this list / collection.
Can someone help