Welcome To Shadab's Blog

Programming Blog to learn C# , java, Sql Server 2005 and many more things.





About Me

My photo
Bokaro, Jharkhand, India

Monday, December 13, 2010

How to call a method through Object?

We hava learnt that what is object ?
Now it is important to note that we can call non-static method through object in C#.

Non-Static Method: Those method which is declare without static keyword are called non-static method.

For Ex :-  public void Add() //here Add is a non static method
               {
                          //method body
                 }

now see this example in which see how can we call non static method through object.

using System;
class Call
{
          public void Add()         //non static method
          {
                  Console.WriteLine("This is Add method");
           }
           public static void Main()
          {
                   Call obj=new Call(); //obj is object of Call class
                   obj.Add();                   //calling Add() method through ob
           }
}

//output will be
This is Add method