When should a C# method be made virtual?

In the last post we saw how the behaviour of base and derived classes changes with the presence of the new or override keyword on inherited methods. In this post we’re going to see the impact that this has on class design. Let’s start with some code:

Polymorphism with new and override

What would you expect the console output to be of the following program?

strong.config is now available on NuGet!

strong.config is now available as a NuGet package! To get it, simply search “strong.config” in the package management dialog, or execute the following command in the package management console:

Write your own code snippets in Visual Studio

Code snippets are a great feature in Visual Studio that automate the writing of oft-repeated code. By typing a special shortcut followed by two strokes of the tab key, you get a preformatted template for a commonly-used code segment. (Try it with prop if you don’t know what I’m talking about.) While there are many snippets available in Visual Studio by default, it’s also easy to create your own. Here’s how: Define the code to template For the purposes of this demo, I’m going to create a template to return the result of a conditional ternary operation. The first step is to define what the snippet is going to look like:

return ([something Boolean]) ? [if true] : [if false];