Sunday, November 8, 2009

METHOD WITH RETURN TYPE AND WITH ARGUMENT

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication13
{

class obj
{
public int show(int a,int b)
{

int c = a + b;
return c;
}
public static void Main (String []args)
{
obj ob=new obj();
int d=ob.show(5,10);
Console.WriteLine("the sum is " + d);
}
}

}

METHOD WITH RETURN TYPE AND WITHOUT ARGUMENT

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication13
{

class obj
{
public int show()
{
int a=5;
int b=10;
int c = a + b;
return c;
}
public static void Main (String []args)
{
obj ob=new obj();
int d=ob.show();
Console.WriteLine("the sum is " + d);
}
}

}

METHOD WITH OUT RETURN TYPE AND WITH ARGUMENT

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication13
{

class obj
{
public void show(int a,int b)
{
int c = a + b;
System.Console.WriteLine ("the sum is "+c) ;
}
public static void Main (String []args)
{
obj ob=new obj();
ob.show(5,10);
}
}

}

METHOD WITH OUT RETURN TYPE AND WITHOUT ARGUMENT

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication13
{

class obj
{
public void show()
{
System.Console.WriteLine ("hello") ;
}
public static void Main (String []args)
{
obj ob=new obj();
ob.show();
}
}

}

METHOD CATEGORIES

There are four method Categories

Here you have to concentrate well, because it is very important while doing programming.

There are four method categories
They are:

1) METHOD WITH OUT RETURN TYPE AND WITHOUT ARGUMENT
2) METHOD WITH OUT RETURN TYPE AND WITH ARGUMENT
3) METHOD WITH RETURN TYPE AND WITHOUT ARGUMENT
4) METHOD WITH RETURN TYPE AND WITH ARGUMENT

WHAT IS ARGUMENT

An argument given in the method, can take input through the argument list.

For example,

public int add(int x,int y)

public specifies the access modifier.
int specifies that the return type of this add method is an integer.
It is not necessary that it must be integer, as the parameter is given as int x, int y and it can be any of the data type. Where as we can determine what type it should return by proper conversion.
int x, int y are the arguments of this method.

RETURN TYPE

RETURN TYPE is the type of data, the method is going to give as the result.
i.e. what type of data is bevel
by the method after execution of that method
If particular method is not returning any data, then we have to mention it as void method.

for example,
public void add()
public specifies the access modifier, that this method is public
void specifies that this add method and is not going to return any value
add() method name