Developer community
0 votes
50 views
asked by Guru (24.6k points) 31 57 92 | 50 views

1 Answer

0 votes

 

 
A parameter is a special kind of variable, which is used in a function to provide a piece of information or input to a caller function. These inputs are called arguments. In C#, the different types of parameters are as follows:
Value type - Refers that you do not need to provide any keyword with a parameter.
Reference type - Refers that you need to mention the ref keyword with a parameter.
Output type - Refers that you need to mention the out keyword with a parameter.
Optional parameter - Refers to the new parameter introduced in C# 4.0. It allows you to neglect the parameters that have some predefined default values. The example of optional parameter is as follows:
public int Sum(int a, int b, int c = 0, int d = 0); /* c and d is optional */
Sum(10, 20); //10 + 20 + 0 + 0
Sum(10, 20, 30); //10 + 20 + 30 + 0
Sum(10, 20, 30, 40); //10 + 20 + 30 + 40
Named parameter - Refers to the new parameter introduced in C# 4.0. Now you can provide arguments by name rather than position. The example of the named parameter is as follows:
public void CreateAccount(string name, string address = "unknown", int age = 0);
CreateAccount("Sara", age: 30);
CreateAccount(address: "India", name: "Sara");
 
answered by Expert (13.2k points) 29 44 62

Related questions

0 votes
1 answer
asked by rock Expert (15k points) 15 23 32 | 1.4k views
0 votes
1 answer
0 votes
1 answer
asked by sara Guru (24.6k points) 31 57 92 | 16 views
+1 vote
1 answer
asked by daniel Advisor (5.6k points) 1 7 14 | 143 views
0 votes
1 answer
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

3,754 questions
4,046 answers
117 comments
10,709 users