You can store any type of 'object' in an array.
This is using Contact[], which is an array of Contacts.Code:static void Main(string[] args) { const int NumContacts = 2; Contact[] contacts = new Contact[NumContacts]; contacts[0] = new Contact("Mario", "Catch", "123 ASDF", "555-555-5555"); contacts[1] = new Contact("Luigi", "IHadTo", "123 FDSA", "555-555-5556"); foreach (Contact contact in contacts) { contact.Show(); } Console.ReadLine(); } public class Contact { public string FirstName { get; set; } public string LastName { get; set; } public string Address { get; set; } public string PhoneNumber { get; set; } public Contact() { } public Contact(string firstName, string lastName, string address, string phoneNumber) { FirstName = firstName; LastName = lastName; Address = address; PhoneNumber = phoneNumber; } public void Show() { Console.WriteLine( "Person Information:\n-Name: {0}\n-Address: {1}\n-PhoneNumber: {2}\n\n", FirstName + ' ' + LastName, Address, PhoneNumber); } }
You can set the properties of the Contact to the values of your TextBox's instead of hardcoded strings.




Reply With Quote