C# Instance Constructor Example

Here is an example of instance constructor in c Sharp programming.
 
Here is the code:-=-
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication28
{
    class Calculator
    {
        static int number1,number2,total;
        Calculator()
        {
            number1=10;
            number2=20;
        }
        public void addnumber()
        {
            total=number1+number2;
        }
        public void Displaynumber()
        {
            Console.WriteLine(“The total is::{0}”,total);
        }
        static void Main(string [] args)
        {
            Calculator c1= new Calculator();
            c1.addnumber();
            c1.Displaynumber();
    Console.ReadLine();
   
    }
}
}
 
Program is running in visual basic 2008.

Add Comment