Sign in to follow this  

Parameter "this" keyword : GetBottomCenter(this Rectangle rect)

This topic is 3291 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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".

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 3291 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this