C# Generic List - Address Book example
To practice generics I made Console Application - Address Book. It's very simple, but it shows the basics.
The functional requirements for application
The menu from which you can choose five options:
1. Add new contact
User inserts contact information
Application reads user input
Storing user input into object properties
Adding object to the list
2. Delete contact
User enters search parameters
Finding contact in list
Removing contact from list
3. Search contacts
User enters search parameters
Finding contact in list
Display data
4. Show the list of contacts
Going through the list
Checking the conditions
Display data, if the condition is met
5. Exit application
Calling the break statement that terminates the while loop
- while loop is for the menu code to be constantly executed.
Creating Menu:
When we run the aplication we see the options but we can't use it
We have to define methods that are colled by choosing a number. But first, we need to create something where we are going to hold the lists of constact, in this case I used generic list LIST:
Now we have to create where to hold contact data (properties). We create new public class Contact with two properties, Name and City (you can put as many as you want, e.g. address, phone… ):
Creating Methods
Put the menu code into while loop in order to be constantly executed. To menu code add additional code that enables you to check the entry. I used if statement, but you can also use switch statement.
Here is the link to whole code for this application. I made some small changes - repeating code in one place.
https://gist.github.com/idukic/5796716












