C# (C Sharp) 1st Program and Terms
Now, we will create a simple program to print a message and will under stand the terms used in C#. Before start i am declaring some of the points which actually necessary in terms of C# programming.
These are below :
- Namespace
- C# Class
- Methods in Class
- Class attributes
- Main method
- Statements and Expressions
- Comments
We will discuss all of the pints one by one using this simple console application program:-
Here select choose 2nd option i.e. "Console App (.Net Framework)". Provide name of your application under "Name :" and select the location where you want to save your project/application and Click Ok button. Our console application will open as below.
Here is out 1st Program in which will discuss all the term.
Namespace
In C# program on the top of the program we access namespace. Namespaces are the library which contains the definition of either predefined methods or attributes or keywords of C#.
As we can see above we are accessing name space with "using" keyword followed by name of namespace and end with semicolon ";". In program we can have multiple namespace as per the requirement.
In this program we using System namespace which already defined in C# library.
At program label we can also define our namespace. Here "My1st_ConsoleApp" defined as namespace.
C# Class
Class is the main container of C# application. It contains the variable, methods. It is the real time entity.
In C# we declare class named as Program.
Method in Class
Here in the above program, there is a Main method which is entry point of C# console application. C# program from Main method always.
Statement & Expression
Inside the C# (e.g. Main) method write multiple lines of code which called Statement and write some of the logic e.g. to add, multiply two numbers are called expressions.
In this program, below line of code is statement which write a message on screen
Console.Write("This is 1st C# Program");
Comments
In C# we define line of comments in two ways. Line of comments ignore by the C# compiler during compilation of Code.
- Single line of Comments
- Multiple line of comments
Single Line of Comments
We define single line of comments using double slash i.e. // line of comment here .
Multiple Line Of Comments
In C# multiple line of comments define using /* ----- Multiple Line of Comments ----- */. Multiple line of comments start with /* and end with */
In both cased Single line or multiple line of comments C# compiler ignore these line during program compilations.
The output of the above program is
This is 1st C# Program.
In the below image all used term in the above program so user can have better understanding.
No comments:
Post a Comment
If you have any doubt please let me know..