C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

what is output parameter and parameter array?


Posted Date: 28 Sep 2008      Posted By: partha chowdhury      Member Level: Silver     Points: 1   Responses: 2



what is output parameter and parameter array?




Responses

Author: Selva    28 Sep 2008Member Level: SilverRating: 4 out of 54 out of 54 out of 54 out of 5     Points: 6

Hi
Do u mean out parameter ?
Out paramater is used for passed by reference. It is similar to ref keyword except ref requires the variable to be initialized before use.

Example
public static void Sum(int a, int b, out int c)
{
c = a + b;
}

int a;
Sum(10, 20, out a);

but params lets you to specify a method that taking invariable number of input parameters

Example

public static int Sum(params int [] Input)
{
int Total=0;
for (int i = 0; i < Input.Length; i++) Total += Input[i];
return Total;
}

int Total = Sum(100, 200, 200, 300);



Author: Vivek    29 Sep 2008Member Level: GoldRating: 4 out of 54 out of 54 out of 54 out of 5     Points: 6

Hi,
Output parameters are like reference parameters, except that they transfer data out of the method rather than into it. They are similar to reference parameters.
Like a reference parameter, an output parameter is a reference to a storage location supplied by the caller. However, the variable that is supplied for the out parameter does not need to be assigned a value before the call is made, and the method will assume that the parameter has not been initialized on entry.
Output parameters are useful when you want to be able to return values from a method by means of a parameter without assigning an initial value to the parameter.

Params (Parameter Array)-

A method that can accept a varying number of parameters. In C#, you can use the params keyword to specify a variablelength
parameter list.

static long AddList(params long[ ] v)
{
long total;
long i;
for (i = 0, total = 0; i < v. Length; i++)
total += v[i];
return total;
}

long x = addlist(12, 14, 16);



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : what is the difference between passing a value object by reference and a reference object
Previous : How to throw an caught exception from cath block?
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use