How do I learn to code using the C-sharp programming language on my Mac?

C# (pronounced "c-sharp") is a great coding language that works across Mac and PC. Programmers use C# to build a variety of applications, especially in the Windows environment.

C# is only one language inside Microsoft's .NET framework, but since Windows 8 it's become the biggest one. Windows developers head straight to C# for building applications on Windows desktop.

Read next: Learn to code in C on Mac | Learn to code in Python on Mac | Learn to code in SQL on Mac

In this feature we'll look at the following:

  • Learn C# in OS X: what is C# and why should you learn to program in it?
  • How to set up C# in OS X
  • Set up MonoDevelop IDE in OS X
  • Learning C# in OS X

So why would you want to learn C# on a Mac? There are lots of reasons for flexing your coding skills towards C#. While C# is tied to the Windows environment, it's cross-platform so that you can learn it just as well on a Mac as a PC.

C# is also a good language for people looking to get into games development. You use Unity, a 2D and 3D game engine and framework with C# (or JavaScript). You can use Unity to develop games for all platforms, including iOS. The close ties to Unity makes C# a good choice for the would-be game developer.

Even if you're a Mac person through and through, C# is an excellent programming language, with modern features such as Delegates, Yield statements, and Lambdas. Microsoft is firmly behind mobile and desktop development, and it's the future of development on Windows. It's worth learning C# if you ever plan to develop programs for both OS X and Windows, or to take apps from one platform to another.

Plus, even if you're an Apple fan, it's always good to see what the competition is up to.

Updated 20 November 2016: For the first time, Microsoft now supports Virtual Studio 2017 on Mac and from 5-11 December 2016 Apple will be running a free 'Hour of Code' workshops, teaching you the basics of CS, Swift Playgrounds and how to write code. You can sign-up to these free workshops through Apple's website.

See also: How to write apps with Swift 2 | Best Mac for app development | How to make an iOS game

Learn to code with C-sharp on Mac: Setting up C#

Learn to code with C-sharp on Mac

Unlike with Python or C, you'll need to install C# on your Mac. Typically you'll do this via an IDE (Integrated Development Environment).

On Windows, you would typically use the Microsoft VisualStudio IDE (Microsoft's equivalent of Xcode). It's worth mentioning that you can install Visual Studio IDE using Windows in a virtual environment on a Mac or even get Visual Studio 2017 for Mac, where for the first time ever Microsoft announced its compatibility on Mac platforms!

However, if you're looking to start out, we would suggest the slimmed-down program called Microsoft Visual Studio Code: this is a code editor with built-in GitHub and debugging support. It's a free download for OS X (and Windows or Linux).

You will need a Visual Studio C# extension to debug code in C#, though. Although that is easy to install.

  1. Download Microsoft Visual Studio Code from the Microsoft website.
  2. Drag the Visual Studio Code app to your Applications folder.
  3. Open Visual Studio Code.
  4. Press Command-P.
  5. Enter "ext install csharp".
  6. Click Restart Now.

When Visual Studio Code restarts, click on Plain Text in the bottom-right and choose C# from the list of available languages. You'll now be able to write C# programs on your Mac inside Visual Studio.

Learn to code with C-sharp on Mac: Set up MonoDevelop to create C# programs on a Mac

Learn to code with C-sharp on Mac: Install MonoDevelop in OS X

Visual Studio Code is perfect for writing C# programs, but you can't compile and run them. It's a code editor, not a full IDE.

To compile and run C# programs you'll need an IDE, MonoDevelop is the one to get. Download a copy of XamarinStudio (MonoDevelop coupled with Xamarin iOS/Android plugins) from the MonoDevelop website:

  1. Go to MonoDevelop and click Download Xamarin Studio under OS X.
  2. Double-click "XamarinStudio-" (or later) in the Downloads folder.
  3. Drag Xamarin to the Applications folder.
  4. Double-click Xamarin in the Applications folder.
  5. Click Download Mono Framework. It will open the Mono Project.
  6. Click Download Mono Universal Installer.
  7. Double-click "MonoFramework-MDK-" file to open it.
  8. Click Continue and follow the Mono Framework installer instructions.

When the installation has finished, return to the Applications folder and open the Xamarin Studio library again.

Learn to code with C-sharp on Mac: The best online courses

Now that you've got C# set up on your Mac, you're ready to start learning the C# language in more depth. There are a bunch of great sites, and online courses, ready to help. Here are some of the best to get you started:

  • C# Tutorial for Absolute Beginners. This YouTube tutorial is a good way to get started.
  • Udemy C# for Beginners. Udemy's C# courses are among the very best, and this is a thorough grounding in the C# language.
  • Unity Scripting. Because Unity is one of the primary environments for using C#, it makes sense that Unity would have some good C# documentation. And it doesn't disappoint.
  • Microsoft C# Programming Guide. It's no surprise that Microsoft has some great C# tutorials available either. You'll find some great information about C# on the Microsoft website.