Tuesday, March 27, 2012

Learning to Code - C# Hello World

Links:
Learning to Code - Introduction

Start

Open Notepad on your windows operating system of choice.
Type the following code into your Notepad window:

 class HelloWorld  
 {  
   static void Main()  
   {  
     System.Console.WriteLine("Hello, world!");  
   }  
 }  

Now save this file as HelloWorld.cs

Now you have a "program" it is a really simple console application that will show the words "Hello, world!" when it is run.  But the first thing we have to do is to convert the human readable file (Specifically in the Microsoft .Net C# language) to one that can be read and executed by a machine (Binary Code, think lots or 1's and 0's strung together).  This is called "Compiling" and the program that is used to compile this is called CSC.exe.

The compiler can be found at the following location(s) on your computer depending on what version of the .Net compiler is installed :

The x86 locations are...
C:\Windows\Microsoft.NET\Framework\v2.0.50727
C:\Windows\Microsoft.NET\Framework\v3.5
C:\Windows\Microsoft.NET\Framework\v4.0.30319

The 64bit locations are...

C:\Windows\Microsoft.NET\Framework64\v2.0.50727
C:\Windows\Microsoft.NET\Framework64\v3.5
C:\Windows\Microsoft.NET\Framework64\v4.0.30319

Open up either a DOS window, or if your a power user you can open a Powershell window.
Change to the directory where your HelloWorld.cs file is, for example on my machine I would type:

CD D:\jp\prj\HelloWorld

Then call the csc.exe file at the location you chose with one paramater which is the name of your C# Helloworld file for example:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe HelloWorld.cs

This will compile your file into a file that can be executed from your DOS console. It will be named HelloWorld.exe

Now you can run your first C# console application


HelloWorld.exe
Hello, world!

Next we will examine just what that code is doing.









Monday, March 26, 2012

Learning to code - Introduction

So you want to be a 1337 HAX0R with MAD SK1LZ? (Whats this?)

Want to create a simple family website with simple tools?

Want to create a more complex website with more advanced tools?

Want a deeper understanding about what "Programming" or "Coding" is all about?

Well hopefully this series of articles will help you out.

The Approach

Personally, I am fairly new to blogging so I will be learning new blogging tricks along the way.  When I want to learn some new technology, I appreciate simple blogs with lots of examples so this is how I will approach teaching how to write code.  However I will intersperse the article with helpful links that may explain a given subject in more detail for those that wish it.  But if you just want your computer to be able to "do stuff" you should be able to get up and running in no time.

For these articles, the most accessible language and environment I can think of is the Microsoft .Net platform. It supports multiple languages and can be used with a simple Notepad editor to start creating programs right away.  It also has a free version of its IDE (Integrated Development Environment) that can be downloaded and take writing software to the next level.

Lets Start - Hello World

The classic program that all software developers use when starting a new language is "Hello World". This is simply getting enough knowledge of a new language that you can output the words "Hello World" to the computer screen. (Geeky History of HelloWorld)  (HelloWorld in a variety of Languages)

I want to follow the C# coding path

I want to follow the HTML (web sites) coding path