Archive for the ‘C#’ Category.

From Zero to ‘Hello, World!’ with C#

For the past year, or so, I have been diving head first in to Microsoft’s Azure cloud service platform. I started with infrastructure as a service (IaaS) and as I expected, it wasn’t much different that what I had been doing for the past decade and a half. Virtual machines and virtual networks in Azure aren’t much different than virtual machines and virtual networks on any other platform. The real value that Azure and many other cloud service providers offer is Platform as a Service or PaaS. The ability to build applications without having to worry about the underlying infrastructure. Focus on building cool stuff and let Microsoft, Google, Amazon, et al., worry about managing the hardware resources, operating systems, etc. Simple, right? Not exactly. I have spent the majority of my career racking, stacking, building out physical infrastructure, configuring virtualized environments, and then… well… no ‘and then’. Don’t get me wrong, I LOVE my job. I love unboxing a pile of shiny, new, expensive things (that I didn’t have to buy my self) and making it all work. However, as they say, times are a changin’. I want to learn how build cool [software] stuff. That’s way too broad. I need to focus…

I want to learn how to develop solutions on Microsoft’s Azure Platform, specifically around their many Platform as a Service offerings.

That’s better.

I have decided to start this adventure by learning the basics of C# (pronounced ‘see sharp’ and sometimes referred to as .NET). Microsoft has done a great job of providing development compatibility for many of the major programming languages. However, I have found that most of the documentation and tutorials that exist today are focused on C#.

Let’s get started.

Install Visual Studio 2017 Community Edition (Free)

Go to http://visualstudio.com and download the ‘Community Edition’. During the install process, you will need to choose which workloads you would like to develop. For now, choose ‘ASP.NET and web development‘. Once the install completes, launch Visual Studio. You should see something like this:

Visual Studio

Create a new Visual Studio project

Navigate to File, New, and select ‘Project…’, select ‘Console App (.NET Core)‘ and name your project ‘HelloWorld‘.

VS New Project

At this point, you should see your new project workspace. Visual Studio creates some boiler plate code to get you started.

Hello World

Modify the ‘Program.cs’ code

Add the following statement to the ‘Program.cs‘ file: ‘Console.ReadLine();‘ on the line below ‘Console.WriteLine(“Hello World!”);‘. Note: C# is a case-sensitive language.

Read Line

Click the ‘Save‘ icon in the toolbar to save your modifications.

Run your ‘Hello World!’ program

Click the little green triangle in the main toolbar.  A console window should pop up and you should see ‘Hello World!’.

Hello Console

The ‘Console.ReadLine’ statement we added is causing the application to wait for input. Without this bit of code, the console window closes too quickly.

To close the application, click in the console window, and push the enter or return key.

Congrats to those of you following along at home. We just wrote our first program in C#. That was almost too easy. I guess we have to start somewhere, right?

I’ll be posting my code over on Github for reference. You can find my Github profile over here: https://github.com/seanluce

Here are a few learning resources that I have found:

Questions? Comments? Helpful advice for a developer in training? Leave a comment below or hit me up on Twitter.