Hi I need some help about C#
I know it is elementary but I don't know how to do that. and also I works without database
I have class User with
string name;
string lastname;
int years;
and then a metod insert ()
{
User us=new User();
name=textbox1.Text;
lastname=textbox2.Text;
years=textbox3.Text;
}
Now for example I need to add(insert) tree(3) users and then write them in listbox, message box or something.
I hope I was clear enough and correctly ask the question
(How to read all instaces of the same class and also I need to sort them by year)

VulpesRank #55 · 29.2K reputationPosted Sep 10, 2014, 3:52 PM EDT
You'll need to set the ListBox's Font property to a fixed width font (such as Consolas) so that the properties line up properly.
I've added two User objects to the ListBox in Form1_Load and you can then add a third (or as many others as you like) by filling out the 3 textboxes and then pressing the button to insert them. They will be automatically sorted by 'years':
Nitesh KejriwalRank #253 · 9.9K reputationPosted Sep 10, 2014, 6:35 PM EDT
Boguda Boguda27 reputationPosted Sep 11, 2014, 1:11 AM EDT
Boguda Boguda27 reputationPosted Sep 11, 2014, 3:03 AM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 11, 2014, 1:42 PM EDT
I added two to start with and additional users can then be added by filling in the TextBoxes and pressing the button.
As you said that the users needed to be sorted by 'years', I assumed that you wanted the whole record to be shown in the listbox. By overriding the ToString method in the User class, we can layout exactly how each record should be displayed so that the properties line up.
Boguda Boguda27 reputationPosted Sep 12, 2014, 1:50 AM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 12, 2014, 6:09 AM EDT
Are you sure that there is something in the texboxes when you click the button?
Also did you remember to add the button_Click event handler via the VS designer rather than manually?