This tip falls squarely into the category of simple, yet oh so useful. Visual Studio 2015 isn’t exactly new, but I am still discovering things that make it nice for debugging. That’s where I’ve spent a lot of my time this week, and one thing that has saved me is using Actions on breakpoints to print messages to the console. And surprise! You can do the same thing even when using auto-properties in Visual Studio 2015 without backing fields.
First, if you haven’t checked out Actions on breakpoints, go ahead and catch up from one of Falafel’s Visual Studio 2015 posts.
An automatic property may look like you can’t set a breakpoint, but you can. In this example we will put one on the setter. Position your cursor after the setter and use the context menu to add a breakpoint.
Printing the Value
Now, how can we print the value getting set to the console? If this were a property with a backing field, we would use the value inside the setter, right?
Well, we can still use the value keyword inside of our Action console statement. Yes, it will work! Intellisense agrees with me.
And voila – we can see the values being set in the console!
Did you learn something? Check out more of Falafel’s blogs covering Visual Studio 2015.