Introduction To C#
In this Tutorial, We are going to write our first C# Program.We are going to learn the basic structure of C# Program. What is a Namespace in C# and what is the use of Main Method in C#
Creating Our First Project
You need to install Visual Studio in your Computer. To make things simple, We are going to learn C# by making Console Applications. So you can use any Version of Visual Studio to practise Programs in this tutorial. Here is the link to download Visual Studio
After installing, Select Visual Studio From Programs. select
File -> New -> New Project ->Visual C#-> Windows ->Console Application
Visual Studio Supports many Programming languages. For C#, Select Visual C# and select windows in the subtree and select Console Application on the right side and click OK.
By Default, Visual Studio provides you some code.As we are learning from the very basics, clear the window by removing the code provided by visual studio
Dissecting our first C# Program
There are some generous developers there at Microsoft who have written so much of difficult code to make things simple to us.They have written so many classes,enums,interfaces,structs and delegates etc and organized them into code blocks called Namespaces.System is one of such Namespace. We can use those wide variety of classes to leverage our application. using System means we are using the namespace for the rest of the program.
We declared a class and named it as FirstProgram. A class groups function members and data members to form an object-oriented building block.We are going to learn more about classes in later tutorials. For now , understand that we write all our methods etc in a class and one namespace can have any number of classes
static void Main()
Main method is the entry point to the application.Main method in our example has empty parentheses because it has no parameters, and is void because it doesn’t return any value to its caller. We are going to learn more about this in later tutorials. A method performs an action in a series of statements, called a statement block—a pair of braces containing zero or more statements. We defined a single method named Main
Console.WriteLine(“Welcome to Become a Geek”);
Console is one of the class comes under System namespace. As we discusses, A namespace is a collection of classes, methods etc. Console comes under System Namespace. console class is used to read or write to the console.Here Console is Command prompt window.WriteLine is a method in Console class which is used to write something to the console.
Console.WriteLine(“Welcome to C# tutorials “);
Statements in C# execute sequentially and are terminated by a semicolon (or a code block, as we’ll see later). The first Statement writes the text “Welcome to Become a Geek” on the screen and it gets terminated by a semicolon and the second statement which is again a writeLine method prints the text which is written in it on the screen.
Every class,Method,Namespace,delegate etc starts with a opening brace and ends up with a closing brace.