Friday, April 19, 2024 06:04

Posts Tagged ‘this’

The meaning of “this” on extension methods

Monday, May 4th, 2020

In the lesson about extension methods, we learned that they are a nice way of adding extra functionality to existing types, and we did that by adding a static method inside a static class, that took a type parameter prefixed with the this keyword, like this:


So, although my original Book class does not contain a method called SellBook(), I am able to call it inside the Main() method because I declared an extension method for the Book class, and this static SellBook() method took a Book type parameter prefixed with the this keyword, that signals the compiler that the method is intended as an extension method for the Book type.… Read more


Follow the white rabbit