What's the meaning of this usage of the this
keyword开发者_运维百科 in C#:
public static ExcelRow Hide(this ExcelRow row)
{
return row.Hide(true);
}
Is this Linq ? If yes, what's the difference between ExcelRow row
and this ExcelRow row
?
In this particular context it denotes that the Hide
method is an Extension Method that can be called on instances of the ExcelRow
type.
It means that it is an extension method. This refers to the instance of ExcelRow for which the method is invoked.
The method you have above is an extension method (msdn.microsoft.com/en-us/library/bb383977.aspx). The "this ExcelRow row" part of the signature means that the method extends an excelRow object. So you can use it on an instance of ExcelRow. Eg: ExcelRow row = new ExcelRow(); row.Hide(); The ExcelRow part of the definition (after the static keyword) simply means that your extension method returns an instance of the ExcelRow Type
精彩评论