Related Posts with Thumbnails

Classes and Object model in .NET

Monday, May 3, 2010

We will start with an introduction to what is object oriented programming, how to write simple classes, creating objects etc.

What is a 'class' ?

In modern object oriented programming, large computer programs are divided into several 'classes'. Typically, a large project will have several hundred classes. A class represents an entity in a program. For example, if you are doing a small program called calculator, you will typically have a single (or more) class called 'Calculator' (you can give any name for your class). The class will have several 'methods', that will do the functionality of the class.

So, your calculator may have methods like the following:
Add()
Subtract()
Multiply()
Divide()

Here is a sample calculator class, written in C# :



using System;

public class Calculator
{
             public int Add(int value1, int value2)
             {
                        return value1 + value2;
              }

             public int Subtract(int value1, int value2)
             {
                       return value1 - value2;
             }

             public int Multiply(int value1, int value2)
             {
                      return value1 * value2;
             }

            public int Divide(int value1, int value2)
            {
                     return value1 / value2;
            }
}


Classes and objects

[To be added.]

Object model in .NET

[To be added.] 

0 comments:

Post a Comment

Site Rate