Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we put "this" in front of a parameter?

Tags:

c#

For ex:

public static Domain.Recruitment.Recruitment Map(this Data.Recruitment dv) 
{
 //some code
  return new Domain.Recruitment.Recruitment{} 
}
like image 963
sahaj_marg Avatar asked Feb 10 '10 06:02

sahaj_marg


People also ask

What is this parameter used for?

A parameter is a useful component of statistical analysis. It refers to the characteristics that are used to define a given population. It is used to describe a specific characteristic of the entire population.

What does this () do in C#?

this (C# Reference) The this keyword refers to the current instance of the class and is also used as a modifier of the first parameter of an extension method.

What does * mean in Python argument?

Python has *args which allow us to pass the variable number of non keyword arguments to function. In the function, we should use an asterisk * before the parameter name to pass variable length arguments.

How do you write a parameter?

To specify parameters in JavaScript, we write the name of the parameter (or parameters) inside the parentheses that come after the function name. We then reference that parameter name inside the function. Now we can call that function and pass our desired value for the parameter: sayHello("Jackson"); sayHello("Mr.


2 Answers

It marks the method as an 'extension method' that can be called like an instance method on an object and allows you "to 'add' methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type":

  • http://msdn.microsoft.com/en-us/library/bb383977.aspx
like image 130
Michael Burr Avatar answered Oct 09 '22 13:10

Michael Burr


Adding "this" to a parameter creates an extension method. An extension method acts like an instance method in that you can call it on instances of the type of the first parameter in the extension method.

For example, the following is possible since Map is marked as an extension method

Data.RecruitMent dv = ...;
dv.Map();
like image 21
JaredPar Avatar answered Oct 09 '22 14:10

JaredPar