What is a parameter? Explain the new types of parameters introduced in C# 4.0.

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:
    [/crayon]
  • 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:
    [/crayon]
Tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.