What can C# be used for?

DevToolsGuy / Thursday, August 7, 2014

Over the last few weeks, we have looked in depth at C#, including a guide for those just starting out with the language. In this post, we are going to look a little more at what type of projects C# can be used for, and the type of code the languages particular features make it most suitable for.

So what can C# be used for? Well, in short, almost anything. It is flexible enough to power TCP/IP Servers, the humble Raspberry Pi and everything in between.

C# does, of course, have particular strengths. The first mention should go to Windows application development. Such is the support for .NET on the Windows platform that C# is now pretty much every developer's first choice for building Windows desktop applications.

Windows 8 has done much to accelerate this adoption. The vast majority of third-party apps in the Windows store are written in C#. Whilst the store has yet to see the same popularity or success as Apple's iOS mobile equivalent, it is undoubtedly the future of Windows application distribution. C# certainly has a bright future on Windows.

C# also supports the creation of web applications, typically via WebForms and MVC. ASP.NET MVC is a powerful modern way to create applications based on the model-view-controller architectural pattern. MVC describes a way to structure an application. The Model handles data and logic, View is concerned with the presentation of that data to the user, and the Controller looks after user inputs. ASP.NET MVC was opened sourced in 2009, and version 5.1.2 was released in April 2014.

The Microsoft ‘All-In-One Code Framework’ is another invaluable resource for web developers interested in exploring the use of C# for web applications.

When it comes to mobile, C# is becoming increasingly popular. Xamarin is leading the way in this area, offering cross-platform tools for all of the major mobile platforms. MonoCross is an alternative implementation, though the project has gone a little quiet of late.

O’Reilly, longtime publishers of developer and technical focused textbooks, also make available a useful resource in the form of ‘Mobile Development in C#’.

Microsoft is also very much behind C# on mobile devices. It has recently released an update to Visual Studio 2013 which supports ‘universal apps’ - that is apps developed side by side for both Windows desktop and Windows mobile devices.
No post of this type would be complete without looking at some of the technical features that make C# useful for modern development projects. There are a huge number of features and functions provided by C#, but three that we think stand out are:

  • Delegates - A delegate is a type-safe function pointer, representing references to methods with a particular parameter list and return type. Delegates can represent instance methods as well as static methods (standard function points are limited to the latter). Unlike pointers in languages like C++, delegates are object-oriented and secure. Delegates are used to pass methods as arguments to other methods, and as such are ideal for defining callback methods.
  • The Yield keyword - With C# 2.0 Microsoft introduced the Yield keyword, which allows any dataset to be exposed as an enumerable list (and iterated with a for each loop). One of the great uses for the Yield keyword is it removes the need for an explicit enumeration class.
  • Lambdas - Version 3.0 of the .NET Framework introduced Lambdas, an anonymous function that can be used to create delegates or expression tree types. Lambda functions are very useful when writing LINQ query expressions.