After Listening about the topic passing parameter mechanism in C#.net, first i feel very difficult but after reading and doing some practical examples i feel very easy.The Parameter passing mechanism plays key role in program development so first concentrate on some tips for parameter passing.Here i am not only placing definition i place My practically doing examples.
Here i Covering the topics are Introduction about parameter passing,what is parameter, how parameter helpful to us,types parameter passing, and types of parameter passing mechanism.
Actually the passing parameter mechanism same in C#.net and Java but the examples are different.C#.net develpers just follow this concept and Java developers or learners just modify your examples in java process.
Actually the passing parameter mechanism same in C#.net and Java but the examples are different.C#.net develpers just follow this concept and Java developers or learners just modify your examples in java process.
Passing Parameter Mechanism
Parameter Passing easy to understand But when develop C#.Net program at that time confusion is came Which Parameters is pass or at this time parameter passing is necessary or not.so,you want get more clarity on parameter passing we simply develop any project with short period so,friends please concentrate on the below topic i write clear description about parameter passing i hopeful it is understand to all and also helpful in interview purpose.
*****Introduction about Parameters*****
Introduction about Parameter
Passing a value to function is called as passing parameter mechanism
What is parameter?
A variable which is declared with in the method signature is called as parameter.
Why Parameter?
Whenever a method is required some value for it's functionality from outside we will go for parameter.
Types of Parameters:-
In C#.net we have two types of parameters.
1.Formal Parameter
2.Actual Parameter
*****Types of parameters*****
1.Formal Parameter
called function parameter is formal parameter.
*****Formal Parameters*****
2.Actual Parameter
Calling function parameter is actual parameter.
Ex;-class Myclass
{
internal void add(int a,int b)//called function,formal parameters
{
int c=a+b;
Console.WriteLine("result is:"+c);
}
}
class Program
{
static void Main()
{
Myclass obj= new Myclass();
int x=10;
int y=20;
obj.add(x,y);//calling function,actual parameters
}
}
**************Actual Parameters*****************
C#.net will support three types of passing parameter mechanism
1.Call by value
2.Call by reference
3.Call by out
1.Call by value
In call by value when formal parameters are modified the modifications will not be reflected back to actual parameters.
In call by value while passing the parameter we will pass the actual value.
Ex:-class Myclass
{
intenal void PayFee(int a)
{
a=a+1500;
Console.WriteLine("a value is:+a);
}
}
class Program
{
static void Main()
{
Myclass obj=new Myclass();
int x=1000;
obj.PayFee(x);
Console.WriteLine("X value is:"+x);
Console.ReadLine();
}
}
*****call by value in parameter passing*****
2.Call by reference
In call by reference when formal parameters are modified those modifications will be reflecting back to actual parameters.
In call by reference while passing the parameter we will pass the address of value.
Ex:-class Myclass
{
intenal void Add(ref int a)
{
a=a+1500;
Console.WriteLine("a value is:+a);
}
}
class Program
{
static void Main()
{
Myclass obj=new Myclass();
int x=1000;
obj.Add(ref x);
Console.WriteLine("X value is:"+x);
Console.ReadLine();
}
} *****call by reference parameter passing*****
3.Call by out
call by out is same as call by reference,In call by out also when formal parameters are modified those modifications will be reflecting back to actual parameter.
While passing parameter or while catching parameter we should use out keyword.
In call by out also with the help of parameter we will pass the address.
out parameter is not required to initialize,If we initialize also CLR will ignore that value.
Ex:-class Myclass
{
internal void PayFee(out int totfee)
{
int admFee=1500;
int semFee=1200;
totFee=admFee+semFee;
Console.WriteLine("total fee is:"+totFee);
}
}
class Program
{
void Main()
{
Myclass obj=new Myclass();
int x;
obj.PayFee(out x);
Console.WriteLine("x value is:+x);
Console.ReadLine();
}
} *****call by out parameter passing*****
Are you Looking For More Topics on C#.Net please visit My Previous Post i feel those are helpful to you
Logical Programming Examples on whileloop
0 comments:
Post a Comment