Method Parameter in C#

C# is having 4 parameter types which are:
  1. Value Parameter : Default parameter types.Only Input
  2. Reference (ref) Parameter : Input / Output
  3. Output (out) Parameter 
  4. Parameter (params) Arrays
Value Parameter
     Are used for passing parameters into methods by value.When a method is invoked, the values of actual parameter are assigned to the corresponding formal parameter. The values can be changed with in the method. The value of the actual parameter that is passed by value to a method is not changed made to the corresponding formal parameter within of the method. This is because the methods refer to only copies of those variables when they are passed by value.

Reference Parameter (Pass By Reference)
     Used to pass parameters, a reference parameter does not create a new storage location. Instead it represents the same storage location as the actual parameter used in the method invocation. Reference parameter is used in situations where we would like to change the values of variables in the calling method.

Output Parameter
     Used to pass results back from a method. Achieved by declaring the parameter with an out keyword. Doesn't Create a new storage location. Instead,becomes an alias to the parameter in the calling method. When a formal parameter is declared as out, the corresponding actual parameter in the calling method. Must also be declared as out.

Parameter Arrays
     Used in method definition to enable it to receive variable no of arguments when called. Declared using the keyword params. Not allowed to combine the params modifier the ref and out modifiers.



If you like this article then put valuable comments.


Comments

Popular posts from this blog

Enable HTTP Transport Security (HSTS) in IIS 7

When to use Truncate and Delete Command in SQL

Steps To Create New Project/Team On TFS