Signup/Sign In

Basic C# Programming

C# is an easy yet powerful object-oriented programming (OOP) language developed by Microsoft Corporation. This high level language can be used for creating a variety of applications like the web, windows application, console-based applications or some other types of applications by using MS Visual studio.

This C# tutorial will give you a sneak peak of the language and will guide you to quickly learn the essentials of C# (before implementing them within Unity 3D). Before going through C#, you have to know the basics of programming (probably using any basic language like C or C++).

NOTE: To proficiently develop games using Unity 3D, you must have beginner level knowledge of C# programming language.


Environment Setup

An IDE (Integrated Development Environment) is a graphical application which helps developers to write programs. Visual Studio is one such IDE offered by Microsoft for writing the code in various languages (that it supports) like: C#, Visual Basic, Visual C++, F# etc. Various versions of Visual Studio are: 2010, 2012, 2013, 2016.

Visual Studio is a licensed application and hence you must have to buy a license for commercial use. But, Visual Studio Express Edition is available for free for students. So, download & install Visual Studio Express from: www.visualstudio.com. Later you have to interlink the Unity Engine with C#, which will be by default the MonoDevelop Editor.

C# can be used in a window-based, web-based, or console application.


First C# Program


using System;
using System. Collections. Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudyTonight
{
    class First
    {
        static void Main (string[] args)
        {
            string msg = "This is 1st C# Program";
            Console.WriteLine (msg);
        }
    }
}

For executing the above program to get the output, you've to compile the program and run it by pressing the keyboard combination: Ctrl + F5 or you can click the Run button or click the Debug menu and then click Start Without Debugging.

Output:

This is 1st C# Program