Monday, February 8, 2010

Methods...

         In general, a method is block of code that helps in performing a functionality. Basically a method looks as follows:
               [modifier] Method_name(Parameters of method){....}
        The modifier can be either an access sepecifier (like public , private etc.) or keywords such as static. The return type may be a value type or a reference type. The parameters are the variables whose scope is local with respect to the given method. These parameters add dynamic functionality to the code written under the method. The methods under the class may be static or non-static.
 Eg: class Hello
{
public int Met(int a,int b)
{
return a*b;
}
public static string Met1(string s)
{
return "Hello"+s;
}
static void Main()
{
Hello h=new Hello();
Console.WriteLine(h.Met(10,2));
Console.WriteLine(Met1("C#"));
}
}