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.
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.
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.
Learn to code with C-sharp on Mac: Setting up C#
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.
- Download Microsoft Visual Studio Code from the Microsoft website.
- Drag the Visual Studio Code app to your Applications folder.
- Open Visual Studio Code.
- Press Command-P.
- Enter "ext install csharp".
- 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
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:
- Go to MonoDevelop and click Download Xamarin Studio under OS X.
- Double-click "XamarinStudio-220.127.116.11-0" (or later) in the Downloads folder.
- Drag Xamarin to the Applications folder.
- Double-click Xamarin in the Applications folder.
- Click Download Mono Framework. It will open the Mono Project.
- Click Download Mono Universal Installer.
- Double-click "MonoFramework-MDK-18.104.22.168.macos10.xamarin.universal" file to open it.
- 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.