Song Lee

Song Lee

  • NA
  • 47
  • 38.3k

Public object to be used in Form.

Dec 29 2014 7:00 PM
Hello, I got question about an assignment that I've been working on for weeks.
Teacher handed back to me, and said m_contactRegistry should not be public.
How will I fix this?
 
ContactManager class with m_contactRegistry: 
 
class ContactManager
{
     public List<Contact> m_contactRegistry; //declare object of the collection
     public ContactManager()
     {
           m_contactRegistry = new List<Contact>();
     }
/// <summary>
/// returns the count of m_contactRegistry
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
     public Contact GetContact(int index)
     {
           if (index < 0 || index >= m_contactRegistry.Count)
           return null;
           return m_contactRegistry[index];
     }
 
 
Form.cs: 
 
private void dltButton_Click(object sender, EventArgs e)
{
     string currContact;
     try { currContact = listBox.SelectedItem.ToString(); }
     catch (Exception) { return; }
     foreach (ContactFiles.Contact c in m_contactMngr.m_contactRegistry)
     {
          if (c.ToString() == currContact)
          {
               m_contactMngr.m_contactRegistry.Remove(c);
               break;
           }
        }
 
 
 
 
Thank you 
 
 
 

Answers (2)