Friday, May 23, 2014

Introduction to C#

I am going to start very simple, because by far I believe it is important to understand these basic concepts and what they do! If you open a new C# Console Application in Visual Studio (free to download and use the Express version!) you will see the following:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello");
            Console.WriteLine("Wonderful World of Software!");
            Console.ReadLine();
        }
    }
}

The console referred to throughout the code is the operating system window (think black screen associated with MS-DOS). This console is what will interact with the referenced System (the operating system). The namespace helps you keep organized and holds your class and method name! System is a namespace. And, Console is a class within the namespace System. By having the "using" directive at the top, it prevents you from needing to specify the actual namespace for every class.

And, importantly.. you require static void Main(string[] args) allows you to tell your program to start reading your code and working!

Class is fun (well-- not school classes, but..)! Classes will describe objects. This goes for all object orientated programming languages, so the great thing is the concepts stay the same and only the syntax changes. Think about how different languages essentially communicate the same ideas, but are written, structured, and spelled differently. Classes are an abstract idea of something that is intangible. Classes have properties which are attributes of it, and methods which are things it can do. An Object is an instance of a class, and it will inherit all of the properties and methods of the class.

Telling the Console to "WriteLine" causes text to be printed on the black output window for you to see. The only reason you can see this though is if you write Console "ReadLine" also (this tells the Console to slow its mega fast computer thinking power down to our human level.. and it will wait for us to input something or to exit the program.. without this text, the program would be inputted, done, outputted, processed, and gone before we could understand what even happened). There are also things called Console.Read() and Console.Write(), what these do differently is that they will read/write only the next character from standard input. Whereas our selection of Console.ReadLine()and Console.WriteLine() reads everything until the end of the characters (which is usually what we want to do).

I will write more on individual topics later on, I just wanted to introduce the idea at the moment!

And, finally.. the world of software is a great place that lives on the Internet and in the great mind of people who build the ideas for it. The Internet is your own free personal library to learn just about anything, including (and especially) what it is built upon! I hope that I can help someone new by explaining it in my own words and coming from how I perceived when it was a new concept. I hope to share many more introductions to software, ideas about it, and snippets of cool new projects.