Professional Documents
Culture Documents
•First c# program
•Printing values
•General form of WriteLine()
•Function, Class and Namespace
•Type of comments.
Introduction to C#
Alphabets,Digits,,Sp symbols
Constants,Variables,Keywords
Statements or Instructions
Programs
• A program is a set of instructions to perform a
specific task.
• Programming languages use programs to
develop software applications.
• A compiler is a special program that processes
the statements written in a particular
programming language and converts them into a
machine language.
• This process of conversion is called compilation.
Tips to write program
All variable must be declared.
+,-,*,/ are Arithmetic Operators
to perform multiplication be must use * instead
of x .
For example 2* 3 is correct
2 x 3 is wrong.
2\3 is not used for division instead of that 2/3 is
used.
A C# program is nothing but a collection of one or more
namespaces.
Inside each namespaces there can be multiple classes, in
short namespaces acts as container which can hold
several classes together.
Each class can contain multiple functions.
Every single class has to belong to some or the other
namespace.so the outer most container is namespace
inside which a smaller container is a class ,inside which a
smaller container called a function and inside the
function there are variables.
The namespaces,class,public,static,void all are
keywords.
C# is case-sensitive and a free form language.
While defining Main() we have to write
as public static void Main()
• C#, also known as C-Sharp, is a programming language
introduced by Microsoft.
• C# is specially designed to work with the Microsoft’s .NET
platform.
Let us understand the structure of a C# program.
Consider the following code example, which defines a class:
public class Hello
{
public static void Main(string[] args)
{
System.Console.WriteLine("Hello, World! \n");
}
}
Classes in C# (Contd.)
System.Console.WriteLine("He
llo, World! \n");
}
}
Accepting and Storing Values in Member Variables
• A C# program
{ can be written by using an editor like Notepad.
ConsiderConsole.WriteLine("Enter
the following code, whichthe Engine
declares Model");
a class Car and
Engine
also creates an=object
Console.ReadLine();
MyCar of the same class:
Console.WriteLine("Enter the number of Wheels");
using System; The using keyword is used to include
NoOfWheels = Convert.ToInt32(Console.ReadLine());
class Car the namespaces in the program.
}
{ Comments are used to explain the
public void DisplayDetails()
//Member variables code and are represented by //
{
string Engine; symbols.
Console.WriteLine("The Engine Model is:{0}",
int NoOfWheels; Member variables are used to store
Engine);
//Member functions the data for a class.
Console.WriteLine("The number of wheels are:{0}",
void AcceptDetails() Member functions are declared inside
NoOfWheels);
} the class that are used to perform a
} specific task.
Creating a Sample C# Program (Contd.)