C Sharp
- Object Oriented
- Platform Independent
- Language Independent
It is used to develop desktop, mobile, websites. It has more than 87 keywords.
How to run a C# program:
There are 3 ways to compile and execute a C# program.
- To use an Online Compiler
- Using Visual Studio IDE
- Using Command Prompt.
#Working with Visual Studio.NET
- it’s an IDE provided by microsoft for developing .Net application.
- It’s used for developing Console, windows, web applications.
- Collection of all the projects together will make the applications
- Collection of all the project is called as Solution
- Solution is a root Elements under which we have all the projects.
- By default the name of the Solution will be the same as name of the Project.
- n number of classes can be added to a program
Namespace
- A name space is a logical container of types.
Logical Container - It doesn’t have a physical existence. Generally it is used for grouping the items.
- By default your project name is the namespace but it can be changed.
- Using statements are used in the beginning of the programs to call the Namespaces.
- Namespaces are used to organise the classes . It helps to control the scope of the methods and classes in larger .Net programming projects.
- Advantage of namespace is that the class names declared in one namespace will not clash with the same class name declared in another namespace.
- it is also referred to as named group of classes having common feature.
- The members of a namespace can be accessed by using(.)dot operator.
- a class in c# is fully known by the namespace.
- in System.Console.WriteLine() “System” is a namespace in which we have a class named ”Console” whose method is “WriteLine()”
- C# provides a keyword “Using” which helps the user to avoid writing fully qualified names again and again. the user just has to mention the namespace once at the beginning of the project and then he can easily avoid the use of fully qualified names.
Nested Namespace:
- We can also define a namespace into another namespace which is termed as nested namespace.
- To access the members of nested namespace user has to use the dot(.) operator.
- ex. Generic is a nested namespace in the collection namespace as “System.Collection.Generic”.
A basic Program consists:
- A namespace declaration
- Class Declaration & definition
- Class members(Like variables, methods etc.)
- Main Method
- Statements or Expression
ex:
using System;
namespace HelloWorld{
class Hello{
static void Main( string [] args){
Console.WriteLine(”Hello World”);
Console.ReadLine();
}
}
}
Explanation
Using System:
System is a namespace which contains the commonly used types .
It is specified with a using system Directive.
namespace HelloWorld:
namespace is a keyword to define namespace .
Hello world is the user defined name given to namespace.
class Hello:
Class is the keyword used for declaration of classes.
Hello is the user defined name given ti class.
static void Main(string []args):
Static keyword tells us that method is accessible without instantiating the class.
Void keyword tells that this method will not return anything.
Main() method is the entry point of a program.
Console.WriteLine():
here WriteLine is method of the console class defined under System namespace.
Console.ReadLine():
This is used in Visual studio.Net. This makes the program wait for a key to be pressed and prevent screen from running and closing quickly.