Category: .NET

8 great features in Visual Studio 2013

In an earlier article I wrote about 10 ways to get more productive in Visual Studio. This is a follow up with new neat things coming with Visual Studio 2013. Open the Resolve menu when typing It happens once in a while that you haven’t included the namespace you need at the top of your

10 ways to get more productive in Visual Studio

Visual Studio is full of shortcuts and handy tools helping you, as a programmer, to be more efficient in your work. Today I’m sharing a few of my favourite ones. All examples given here are tested in Visual Studio 2012. Open search result in a list Press CTRL + F to open the search pane.

Create your own extension methods to use in LINQ

The possibility to create extension methods has been around for some time in the .Net Framework. It basically gives you the possibility to extend a class with new methods without having to create a new class that extends the original one. If the original class is sealed you can’t even extend the class, but you

How to prevent duplicate application instances

Sometimes it’s important to make sure your program isn’t running more than one instance at the time. In C# this is an easy task using the provided .NET libraries. In this short illustrative example the program counts the number of processes with the same assembly name as this current assembly. If any are found, the

Do you know what your C# variables contain?

It might sound like a trivial question but there are several ways to analyse a variable and they might give different answers. It’s therefore good to know what the difference in-between them are. The different tools we’ll go through here are: is, typeof and GetType. To include the complexity of inherited objects we create two

Missing the timer in WPF?

It’s not gone, it has just moved away from being a UI component to become a code class. In WPF it’s called Dispatcher Timer and can be used in the following way: using System.Windows.Threading; public MainWindow() { InitializeComponent(); DispatcherTimer dispatcherTimer = new DispatcherTimer(); // Register method target to execute every tick dispatcherTimer.Tick += DispatcherTimerTick; //

Have you tried the null coalescing operator in C#??

It’s quite handy and can make the code a bit more lean if you need to do a lot of null value testing. Here is a simple example: processCar = inputCar ?? new Car(); What it basically mean is “if inputCar is null then create a new car instead”. The code can be unfolded in

Add a notification icon to your WPF program

I needed to create a WPF program that will run at certain intervals and, when running, always will do it in the background. Not that difficult. But I also wanted it to be accessible through a notification icon down in the right corner on the Windows screen. A little more work, but not that bad.

Complex syntactical sugar using yield in C#

Yield is one of the available contextual keywords in C#, meaning it has a purpose in the code but it’s not a reserved word. Microsoft defines yield as being: Used in an iterator block to return a value to the enumerator object or to signal the end of iteration The keyword was added in .NET

Implement a complex type in MVC4 and EF

When you create models in Entity Framework you have the possibility to generalize parts of it into reusable types by adding the ComplexType attribute. To illustrate I have a made up example of an access definition type that can be used on many different user-to-something connections to define what kind of access the user has.

%d bloggers like this: