Adding Members to the Classes in the Sample Code


Adding Members to the Classes in the Sample Code

Now that you know about the various members that classes can have, it's time to make the classes in the sample code more functional.

To add members to the classes in the sample code:

  1. Right-click the file entertask.aspx in Solution Explorer, and choose View Code from the context menu.

  2. Enter the code highlighted in Figure 2.79 to your class definitions.

    Figure 2.79 Add the above code to the entertask.aspx file.
     class ToDoItem {    //fields  string item = "";   string description = "";  //properties  public string Item   {   get   {   return item;   }   }   public string Description   {   get   {   return description;   }   }  //methods  public void SetInfo(   string item, string description)   {   this.item = item;   this.description = description;   }  } class ToDoList {    //fields  Hashtable list = new Hashtable();  //methods  public void Add(ToDoItem tditem)   {   list.Add(tditem.Item,   tditem.Description);   }   public void Remove(ToDoItem tditem)   {   list.Remove(tditem.Item);   }  } 

graphics/tick.gif Tips

  • The code in Figure 2.79 adds the fields, properties, and methods necessary to make the classes functional. Notice the use of the information-hiding technique. As you can see both classes use private fields. The classes expose properties or methods to enable the user to manipulate the fields, but the user can't manipulate the fields directly.

  • The application isn't yet complete; see the next section, "Completing the Sample Application."




C#
C# & VB.NET Conversion Pocket Reference
ISBN: 0596003196
EAN: 2147483647
Year: 2003
Pages: 198
Authors: Jose Mojica

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net