Sponsored Links
Microsoft AJAX Tutorials
- Microsoft AJAX Library Essentials
- Concepts of Object-Oriented Programming
- Microsoft AJAX Library - Object-Oriented JavaScript
- Microsoft AJAX Library - JavaScript Functions
- Microsoft AJAX Library - Functions as Variables
- Microsoft AJAX Library - Anonymous Functions
- Microsoft AJAX Library - JavaScript Classes
- Microsoft AJAX Library - C# and JavaScript Classes
- Microsoft AJAX Library - Associative Arrays
- Microsoft AJAX Library - Creating Object Members on the Fly
- Microsoft AJAX Library - JavaScript Execution Context
- Microsoft AJAX Library - Inheritance using Closures
- Microsoft AJAX Library - Inheritance using Prototypes
- Microsoft AJAX Library - Introducing JSON
Home
Tutorials
Microsoft AJAX
Microsoft AJAX Library - C# and JavaScript Classes
Production-quality C# implementation
Tutorials
Microsoft AJAXMicrosoft AJAX Library - C# and JavaScript Classes
Table of Contents
Microsoft AJAX Library - C# and JavaScript Classes
Production-quality C# implementationMicrosoft 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
- public class Table
- {
- // public members
- public int rows = 0
- public int columns = 0
- // constructor
- public Table(int rows, int columns)
- {
- this.rows = rows
- this.columns = columns
- }
- // method returns the number of cells
- public int getCellCount()
- {
- return rows * columns
- }
- }
Copyright exforsys.com
You'd instantiate and use the class like this:
Sample Code
- Table t = new Table(3,5)
- int cellCount = t.getCellCount()
Copyright exforsys.com
Next Page: Production-quality C# implementation
Read Next: Microsoft AJAX Library - Associative Arrays
Comments
Sponsored Links
