Getting Started with C# Programming

C# (C Sharp) is a Microsoft programming language created to compete with Java and C++. C# was developed in 2000 as an object oriented, multi-paradigm programming language within the .NET Framework (a programming library that comes with windows).


C# has become popular over the years as an alternative to Java. Due to its ease of use and visual GUI programming through Visual Studio .NET, it is currently the 4th most searched programming language on search engines (after C / C++, Java, Python, and Visual Basic).

Getting Started

To start learning and developing C#, you need an IDE that can compile your C# applications. Visual Studio .NET, 2008, 2010, or Sharp Develop (free). The express version of Visual Studio is free.

First C# Program

The C# language is very similar to C++ and Java, borrowing elements from both. Every function in C# is in a class and they are all usually in their own namespace (this is for organizational purposes).

Remember that C# is case-sensitive, so be careful with how you type.

using System;
This is a multi-line comment, it is not compiled or used by C# but for easy documentation, if you use "using System" then you don't have to type System.Console.WriteLine, and instead can type Console.WriteLine.

public class MyCSharpClass
   public static void Main(string[] arguments)
       // single line comment
       Console.WriteLine("Number of command line parameters = {0}", arguments.Length);
       for(int i = 0; i < arguments.Length; i++)
           Console.WriteLine("Arg{0} = {1}", i, arguments[i]);

First we declare our own class called "MyCSharpClass" (you can make up a name). The static void Main is an important function that C# looks for in each program to know the starting point of each program (each program must have this).

string[] arguments is an array of strings (a list of strings), that are gathered from the command line arguments.

If your program is named "CoolSharp", then in command prompt you may type "CoolSharp parameter1 parameter2" and that list will contain "parameter1" for arguments[0] and "parameter2" for arguments[1].

Therefore, we loop through the arguments with a "for" loop. And display each argument in the command line. We use arguments.Length property to learn how many parameters the user entered in his console.

Give this a try after you compile an empty project with this source code (call it MyCSharpClass.cs).

int i, is an integer variable that is incremented in the for loop to keep track of how many loops we've made so far. The {0} and {1} are special keywords used to gather the second and third argument from a WriteLine() function.

Learning C#

If you're a beginner to programming C# is a good language to begin. If you constantly run examples, compile them, and edit them you will begin to understand why and how they work. Keep reading more tutorials like this one and check out our C# section.

You may also visit our C# forums and ask for help from experienced programmers that work for companies developing C# applications.

Tomescu Alin's picture

Good introductory article!

Good introductory article!


Get Linux or die tryin'

Baran Ornarli's picture

Thanks alinush. I hope you

Thanks alinush. I hope you enjoyed it. I think you and I should write more C# tutorials.

Bob's picture

Thanks for this, I was

Thanks for this, I was wondering about C# recently.

Kyle's picture

Ah C# tutorials, really cool

Ah C# tutorials, really cool stuff.

Jake's picture

I'd like to see more indepth

I'd like to see more indepth tutorials on C# in the near future! :D.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.