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...






Resources » Articles » .NET Framework »

Parameters in C#


Posted Date: 11 May 2006    Resource Type: Articles    Category: .NET Framework
Author: RamakrishnaMember Level: Gold    
Rating: 1 out of 5Points: 5



Parameters in C#



Parameters: Passing a values to the called function from the calling function

There are four different types of parameters in C#. They are
1. Value parameters
2. Ref parameters
3. Out parameters
4. Parameter arrays (Params)

1. Value parameters

A parameter declared with no modifiers is a value parameter and This is the default parameter type in C#. In this type of parametrs actual value is passed to the function, and the changes made in the function not affect the original value in the calling function.

Eg.

static void fnValue( int i)
{
i = i + 1;
}

2. Ref parameters
Ref parameters are input/output parameters. This type of parameters are declared with the modifier “ref” . these parameters are used to pass the values back and fourth between the called function and calling function. Here the actual reference of the variable is passed to the function.
static void fnRef( ref int i)
{
i = i + 1;
}

3. Out parameters
Out parameters are Similar to a reference parameter, these parameters are declared with the out modifier. Output parameters are typically used in methods that produce multiple return values. The out put parameters can only pass back a value from a function. Every output parameter of a method must be assigned before the method returns.

static void fnOut ( out int k, out int i )
{
k =5;
i=9;
}


4. Parameter arrays
This type parameters are declared with the modifier params. These types of parameters are very useful when we need to pass the number of arguments to the function. In the parameter list the parameter array must be the last parameter. and it must be of a single-dimensional array type. params parameters are input type parameters.







Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Introduction to .NET with Basic Shotcuts and Secrets for the Beginner
Previous Resource: File uploading in asp.net using C# and diplaying in the grid
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use