Free Training
C Language   |   CSS   |   MainFrame   |   VBScript   |   PHP   |   XML   |   C++ Tutorials   |   Ajax   |   JavaScript   |   CSS3   |   UML   |   jQuery   |   Microsoft AJAX

Sponsored Links

Microsoft AJAX Tutorials

 
Home Tutorials Microsoft AJAX
 

Microsoft AJAX Library - C# and JavaScript Classes

 

Microsoft AJAX Library - C# and JavaScript Classes

Page 1 of 2

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:


Sample Code
  1. public class Table
  2. {
  3. // public members
  4. public int rows = 0
  5. public int columns = 0
  6. // constructor
  7. public Table(int rows, int columns)
  8. {
  9. this.rows = rows
  10. this.columns = columns
  11. }
  12. // method returns the number of cells
  13. public int getCellCount()
  14. {
  15. return rows * columns
  16. }
  17. }
Copyright exforsys.com




You'd instantiate and use the class like this:


Sample Code
  1. Table t = new Table(3,5)
  2. int cellCount = t.getCellCount()
Copyright exforsys.com



Next Page: Production-quality C# implementation


Read Next: Microsoft AJAX Library - Associative Arrays



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links