Parameter "this" keyword : GetBottomCenter(this Rectangle rect)
I'm pretty new to C# and I noticed in the xna 3.0 platformer starter project the have the method:
public static Vector2 GetBottomCenter(this Rectangle rect)
{
return new Vector2(rect.X + rect.Width / 2.0f, rect.Bottom);
}
I'm just wondering what declaring a parameter with "this" does, I looked up the keyword on msdn and it only shows the uses I know of, like accessing member variables using this., and when I google it, I just get a bunch of sites about different ways to pass parameter that don't mention using "this".
It's called "Extension methods" and its been introduced with C# 3.0. Googling "C# 3.0 extension methods" will provide you with all the info you need. You can also google "LINQ" for a better understanding of what this language feature permits.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement