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 m_contactRegistry; //declare object of the collection
public ContactManager()
{
m_contactRegistry = new List ();
}
///
/// returns the count of m_contactRegistry
///
///
///
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
Harieswaran DPosted Dec 29, 2014, 11:53 PM
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ContactManager mngr = new ContactManager();
string currContact;
try
m_contactRegistry; //declare object of the collection();
{
currContact = listBox.SelectedItem.ToString();
bool flg = mngr.RemoveCondact(currContact);
if (flg )
MessageBox.Show("Successfully Removed");
}
catch (Exception)
{ return; }
}
}
class ContactManager
{
private List
public ContactManager()
{
m_contactRegistry = new List
}
///
/// returns the count of m_contactRegistry
///
///
///
public Contact GetContact(int index)
{
if (index < 0 || index >= m_contactRegistry.Count)
return null;
return m_contactRegistry[index];
}
public bool RemoveCondact(string str)
{
foreach (Contact c in m_contactRegistry)
{
if (c.ToString() == str)
{
m_contactRegistry.Remove(c);
return true;
}
}
return false;
}
}
public class Contact
{
}
Sibeesh VenuPosted Dec 29, 2014, 11:50 PM
http://www.dotnetperls.com/property
Kindest Regards
Sibeesh
http://sibeeshpassion.com/