alt
Advertisement
Sponsored links
Online Training
Career Series
Exforsys
Exforsys arrow Tutorials arrow Microsoft AJAX arrow Microsoft AJAX Library - C# and JavaScript Classes
Site Search


Microsoft AJAX Library - C# and JavaScript Classes
Article Index
Microsoft AJAX Library - C# and JavaScript Classes
Production-quality C# implementation

C# and JavaScript Classes

For the purpose of demonstrating a few more OOP-related concepts, we'll use another class. Our new class is named Table, and it has two public fields (rows, columns), and one method, getCellCount(). The getCellCount() method should return the number of rows multiplied by the number of columns. The class constructor should receive two parameters, used to initialize the rows and columns fields. This class could be represented by the class diagram in Figure 3-3.

Figure 3-3. Class diagram representing the Table class

The C# version of this class would look like this:

  1. public class Table
  2.  
  3. {
  4.  
  5. // public members
  6.  
  7. public int rows = 0;
  8.  
  9. public int columns = 0;
  10.  
  11. // constructor
  12.  
  13. public Table(int rows, int columns)
  14.  
  15. {
  16.  
  17. this.rows = rows;
  18.  
  19. this.columns = columns;
  20.  
  21. }
  22.  
  23. // method returns the number of cells
  24.  
  25. public int getCellCount()
  26.  
  27. {
  28.  
  29. return rows * columns;
  30.  
  31. }
  32.  
  33. }
 

You'd instantiate and use the class like this:

  1. Table t = new Table(3,5);
  2.  
  3. int cellCount = t.getCellCount();
 



 
< Prev   Next >
Exforsys Offers
© 2008 Exforsys.com
Joomla! is Free Software released under the GNU/GPL License.
Page copy protected against web site content infringement by Copyscape