Interviews - C# Corner

Md. Tahmidul Abedin
Write the name of the three ways to pass a parameter to a method in C#.
By Md. Tahmidul Abedin in C# onOct 22 2018
  • Md. Tahmidul Abedin
    Oct, 2018 22

    1. Value Parameters 2. Reference Parameters 3. Output Parameters

    • 5
  • Madan Bandari
    Nov, 2018 5

    Value Parameters copies the actual value of an argument into the formal parameter of the function. When a simple variable is passed as the parameter to any method, it is passed as a value. This means that the value contained by the variable that is passed as the parameter is copied to the variables of the method, and if inside the method these values are changed or modified, the change is not reflected in the actual passed variable. Most of the primitive data types such as integer, double, Boolean etc. are passed by value.Reference ParametersReference Parameters copies the reference to the memory location of an argument into the formal parameter. Normally, all the objects are passed by reference as parameter to the method. The method operates on the references of the variables passed in the parameters rather than operating on their values. This results in the modification of variables in the calling function when they are modified in the called function. This means that changes made to the parameter affect the argument.Output ParametersOutput Parameters helps in returning more than one value . A return statement can be used for returning only one value from a function. However, using output parameters, you can return two values from a function. The variable supplied for the output parameter need not be assigned a value. Output parameters are particularly useful when you need to return values from a method through the parameters without assigning an initial value to the parameter. Output parameters are similar to reference parameters, except that they transfer data out of the method rather than into it

    • 1
  • Bidyasagar Mishra
    Aug, 2019 4

    value,out,ref

    • 0
  • Harisankar Angamuthu
    Nov, 2018 12

    1. We can pass Argument as parameter to Constructor, Method and by setting as a property. Method will get all three 1. Value Parameters 2. Reference Parameters 3. Output Parameters

    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS