This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Me And My Respected Teacher Mr Kamal Sheel Mishra

Mr. K.S. Mishra is HOD of Computer Science from SMS Varanasi where I have completed my MCA

Me And My Respected Teacher Mr Udayan Maiti

Mr. Udayan Maiti is a senior .Net Expert and has guided many professionals of multi national Companies(MNC)

Me And My Best Friend Mr Ravinder Goel

Mr. Ravinder Goel is a senior Software Engineer and now he is working Wipro Technology

Monday, 30 July 2012

Inheritance with an example in C#.NET


Inheritance with an example in C#.NET

Creating a new class from existing class is called as inheritance. 


When a new class needs same members as an existing class then instead of creating those members again in new class, the new class can be created from existing class, which is called as inheritance.


Main advantage of inheritance is reusability of the code.


During inheritance, the class that is inherited is called as base class and the class that does the inheritance is called as derived class and every non private member in base class will become the member of derived class.

Inheritance can be classified to 5 types.


  1. Single Inheritance
  2. Hierarchical Inheritance
  3. Multi Level Inheritance
  4. Hybrid Inheritance
  5. Multiple Inheritance
1. Single Inheritance

when a single derived class is created from a single base class then the inheritance is called as single inheritance.


2. Hierarchical Inheritance
when more than one derived class are created from a single base class, then that inheritance is called as hierarchical inheritance.

3.Multi Level Inheritance
when a derived class is created from another derived class, then that inheritance is called as multi level inheritance.


4. Hybrid Inheritance
Any combination of single, hierarchical and multi level inheritances is called as hybrid inheritance.

5. Multiple Inheritance
when a derived class is created from more than one base class then that inheritance is called as multiple inheritance. But multiple inheritance is not supported by .net using classes and can be done using interfaces.


Note:Handling the complexity that causes due to multiple inheritance is very complex. Hence it was not supported in dotnet with class and it can be done with interfaces.



Sunday, 29 July 2012

Delegates in C# (Singlecast and Multicast delegates in C#)





Delegates  in C# .NET………………..

What is Delegates  in C #
Delegate is  the special type use to hold the reference of  function ,
Delegate  concept  match  the function pointer concept of  c language

Types Delegates  in C# : There  are two type delegate is  C#

       1.Single cast  Delegate
       2.Multicast Delegate

Single cast Delegates  in C #It is  those delegate which hold the  address of  single method,
               Setp 1: General Syntax to define the delegates

                 Access Specifier delegate Name of delegate in form of  function

 Note: In the   single cast delegate signature of delegate should be same as method for which we are creating for this delegate.

Like:  we create   functions………………………………………………………..

    public int sum(int x, int y)
    {
      return (x + y);
        
   }
    public double div(double x, double y)
    {
          return (x / y);
       
    }

Setp 2: After than  we  create delegate  for  above  function

          public delegate int sumdel(int x, int y);

          public delegate double devdel(double x, double y);


Setp 3: After Procedure to assign reference of function to a delegate

                a. Create object of delegate
                b. Set the object with name of function

           sumdel ob = new sumdel(sum);
           devdel ob1 = new devdel(div);

Note: ob hold the  address of sum method

Setp 4: Procedure to call  a function with  help  of  delegates…………….

                  ob(12,4)                     = 16;
                  ob1(12,4)                     = 3;



Example for Singlecast Delegates.........................



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyDelegateExp
{
    public partial class Form1 : Form
    {
       

        public Form1()
        {
            InitializeComponent();
        }
        public int sum(int x, int y)
        {
            return (x + y);
        }
        public double div(double x, double y)
        {
            return (x / y);
        }
        public int mul(int x, int y)
        {
            return (x * y);
        }
        public int sub(int x, int y)
        {
            return (x - y);
        }

        public delegate int sumdel(int x, int y);
        public delegate double devdel(double x, double y);
        public delegate int multdel(int x, int y);
        public delegate int subdel(int x, int y);


        private void ButtonSingleCast_Click(object sender, EventArgs e)
        {
            double i = Convert.ToDouble(txtfstno.Text);
            double j = Convert.ToDouble(txtsecondno.Text);
            int k = Convert.ToInt32(txtfstno.Text);
            int h = Convert.ToInt32(txtsecondno.Text);

            sumdel ob = new sumdel(sum);
            devdel ob1 = new devdel(div);
            multdel ob2 = new multdel(mul);
            subdel ob3 = new subdel(sub);

            textBox1.Text = ob(k, h).ToString();
            textBox2.Text = ob1(i, j).ToString();
            textBox3.Text = ob2(k, h).ToString();
            textBox4.Text = ob3(k, h).ToString();
        }

     
    }
}

Multicast  Delegates  in C #If you  want  to hold the address of  multiple method in a single delegates  then we  have  to declare  multicast  delegate,
                                          Multicast  delegate  will work only those  method  which have  return type  only  void………………

Like:  we  create   functions………………………………………………………..

      public void sum(int x, int y)
      {
           MessageBox.Show( (x + y).ToString());
       }
        public void div(int x, int y)
        {
        MessageBox.Show((x / y).ToString());
        }
        public void mul(int x, int y)
        {
         MessageBox.Show((x * y).ToString());
        }

       Setp 2: After than  we  create  multicast delegate  for  above  function

                   public delegate void Muldel(int x, int y);
        

      Setp 3: After Procedure to assign reference of  function to a delegate
a.  Create  object  of  delegate
               b. Set  the  object  with name  of function

                 Multicastdel ob = new Multicastdel(sum);
           
                      ob += div;
                      ob += mul;
                      ob += sub;
                      ob(k, h);

        
          Note: ob hold the  address of all methods

        Setp 4: Procedure to call  a function with  help  of  delegates…………….
         
                     ob(12,4)                   Result  = 16,3,48,8;







Example for Multicast Delegates.........................
                   



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyDelegateExp
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        public void sum(int x, int y)
        {
            MessageBox.Show("Addition" + "  " + (x + y).ToString());
        }
        public void div(int x, int y)
        {
            MessageBox.Show("Division" + "  " + (x / y).ToString());
        }
        public void mul(int x, int y)
        {
            MessageBox.Show("Multiplication""  "+(x * y).ToString());
        }
        public void sub(int x, int y)
        {
            MessageBox.Show("Subtraction"+"  "+(x - y).ToString());
        }

        public delegate void Multicastdel(int x, int y);

        private void bMulCastDel_Click(object sender, EventArgs e)
        {
            int k = Convert.ToInt32(txtfstno.Text);
            int h = Convert.ToInt32(txtsecondno.Text);
            Multicastdel ob = new Multicastdel(sum);
          
            ob += div;
            ob += mul;
            ob += sub;
            ob(k, h);
           
        }

    
    }
}