CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 58

Threaded View

  1. #19
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: Display highlighted data from Listbox in Textboxes

    You can store any type of 'object' in an array.

    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);
                }
            }
    This is using Contact[], which is an array of Contacts.
    You can set the properties of the Contact to the values of your TextBox's instead of hardcoded strings.
    Last edited by mariocatch; January 22nd, 2010 at 03:25 PM. Reason: Description.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured