C# - Basic
Why should you learn C# ?
-
Popular language
C# is considered as one of the most popular language in the World.
-
Easy to learn for C++ and C# programmers
As the syntax and features of C# is quite similar to C++ and java. It becomes easy for
C++ and java programmers to learn C#.
-
Object Oriented Programming Language
C# is an Object Oriented Programming Language which provides all the features of Object
Oriented Programming Language that gives a proper structure to your project.
First C# Application
Let us write our first C# Application which just prints 'Hello World'
on the screen.
Example :
public class FirstApplication
{
public static void Main(string[] args)
{
System.Console.WriteLine ("Hello World");
}
}
Output :
Hello World
Let us dissect the above code and understand in detail:
-
So, in the above code we are printing 'Hello World' using the below statement,
System.Console.WriteLine("Hello World");
We do not have to dig much into individual component in the output statement for now.
We can just remember, 'System.Console.WriteLine()' is the statement used to System.Console.WriteLine
something
on the screen.
-
Since, C# is said to be an object oriented programming language. All C# programmes should
be written inside a class. 'FirstApplication' is the name of the class inside which we
have to write our code :
public class FirstApplication
{
...
}
Note : We have a separate tutorial on 'Class'. For now, you do not
have to dive more into
'Class'.
-
Inside the class 'FirstApplication', we have the main() method. The main() method is the
entry point of a standalone C# application. So, C# executes the code written inside the
main() method :
public static void Main(string[] args)
{
System.Console.WriteLine ("Hello World");
}
Since, 'System.Console.WriteLine ("Hello World")' is inside the main() method, it c-sharp-t printed.
Moral of the Story
We have to write all our codes inside the main method. And the main method should be inside a class.
Example :
public class FirstApplication
{
public static void Main(string[] args)
{
//OUR CODE SHOULD BE WRITTEN HERE.
}
}
The next thing that comes to our mind is, where do we write the above C# code? And how do
we run it?
Well! We have the answers in the next tutorial.