Ok let's begin our simple C# project named "Hello world". " Hello world" is usually the first program a newbie or newcomer learn when he/she was new to any platform or language.Here platform may be IDE's or Operating Systems(OS) and languages may be c,C++,C#,Java,Python etc.
To begin a new project.Follow the following steps:
1.Open Visual Studio
2.Click on File
3.Click on New Project
4.Select language C#
5.Select template or project type-Console Application
6.Give a name to your Project.eg-HelloWorld
As default a code editor will open containing some default codes which is provide by IDE itself for our comfort.
Believe me programming in Microsoft Visual Studio is very easy due to this default codes (no need to type same codes for every application) & ' Intellisense ', for example , if you are attempting to write a code "Console.WriteLine()".After typing "console." & "w" .WriteLine will appear itself & you can press enter or other letters after WriteLine to use that word.
Let's code our "Hello World" Programme:-
//I am a comment you must know ,i will describe working of any code..
//------Code Start-------------------------
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.ReadLine();
}
}
}
//---------------Code End--------------------------
In your IDE you code will look like this
Let's understand each and every part of above code in detail.
Using keyword is used to include any directives or header files or namespaces.Directives are required by our applications to use any function.
for eg- Console.WriteLine();
WriteLine() is a function.Console is a class.System is a namespace.System is a collection of classes like console.So we can say namespace is a collection of similar classes.System namespace must be there in every console I/O operation.
Previously we discuss about the namespace 'System' . So what's difference in between System and HelloWorld namespace? So here is a difference,System is defined by IDE & HelloWorld is defined by ourself .Suppose you are doing system programming i.e. developing Operating System(OS) yourself ;).At that time you could not use any directives or namespace.You have to define yourself each and every work or functions.Since we are doing application programming ,we require some pre-built functions thats why we use namespace like System.So why there are these namespaces,classes,functions, etc.These all are parts of OOP(Object Oriented Programming).Class contain functions and data.Whereas namespace contains similar classes i.e namespace is a grouping of similar classes.
This curly starts the definition of HelloWorld namespace.
This is a class which contains some function or any data.Here we are using only function .eg-'Main()' function.'Program' is optional you can give any name like in namespace naming.
This curly starts 'Program' class definition.
Here, 'Main' function is a starting entry point of application.Like your first line of notebook.Since C sharp(C#) is a case sensitive programming language,So M must be capital in Main.Oh! i forgot to tell our 'System' namespace's 'S' is also Capital ;)
Here Void means our function does not return anything.That is nothing in response to that point
from which our function is called.Since Main() will not be called from any other part of our program.Since it is a entry point of our application.
So now 'Static', static functions are those functions which does not require any instance identifier.They are called with the type name.By reading this please don't get into complexity on this very first program.Whole chapter may create dealing with static.You only have to know at this time is that
this "static Void Main()" line is a entry point of our application and each application must have a Main() function.
This Curly brace stats our function definition.
Console is a class under System namespace .WriteLine() is a function defined in console class.
Dot or period is used to access the function of any class.Console means DOS like screen.To print
any message on that screen or window we use Console.WriteLine() function.Hence WriteLine function is used to write a Line in screen.If you only use Console.Writr() instead of WriteLine(), a line will not be breaked.
The message or string must be inside double quotations.Since it is a string(eg "Iphone") ie combination of 'characters(eg 'I') .Belive me nohing is basic before this :( .Braces are of WriteLine function.There will not be any function without braces,so if there is anything inside braces then that is a parameter or arguments on which the function depends or works.
ReadLine() is actually for reading a line typed by user.But here we use
it for holding the screen for a while to see the output untill user presses a enter key.Then why to hold screen?(Ans:Try skipping this line you will notice ;) ).oh yea another basics goes here for semicolon(;).Semicolon at last indicates that one statement or command for the computer is finished haha :)
each namespace ,class & function must start & end with matching curly braces.
So,this is a end of our hello world program. i hope you guys learn a basics in very easy & rocking way.See you in next post ,ba-bye tc :)
No comments:
Post a Comment