Exforsys.com
 
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

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2010 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape