Professional Documents
Culture Documents
.NET Framework
Introduction to C#
C# (pronounced "C-sharp") is an object-oriented programming
language from Microsoft that aims to combine the computing power
of C++ with the programming ease of Visual Basic.
C# is based on C++ and contains features similar to those of
Java. C# is designed to work with Microsoft's .NET platform.
Developed by Anders Hejlsberg(Microsoft).from Denmark.
Based on Java and C++, but has many additional extensions.
Cont
Cross-development with Visual Basic, Visual C++, F#, IronPython,
and many other .NET languages.
C# syntax derived from C++ and java.
The basic syntax of C# comes from C++.Where structure is inherited
from java.
Just like virtual machine for java. The .NET CLR can provide many
features including automatic memory management and garbage
collection.
Overview
The following reasons make C# a widely used professional
language:
Modern, general-purpose programming language.
Object oriented.
Easy to learn.
Structured language.
Produces efficient programs.
Part of .NET Framework
Why C#
It has been designed to support the key feature of .NET framework.
It is great language for programming as it offers several key benefits for
programmers.
They are,
Simplicity
consistency
Flexibility
modernity
object orientation
Scalability
Various support
In this session
Basic structure of a c# program.
What is a Namespace.
Purpose of Main method.
Simple Program
Program Explanation
The first line of the program using System; - the using keyword is used to include
the System namespace in the program. A program generally has multiple using
statements.
The next line has the namespace declaration. A namespace is a collection of
classes. A namespace is used to organize your code.
The HelloWorldApplication namespace contains the class HelloWorld.
The next line has a class declaration, the class HelloWorld contains the data and
method definitions that your program uses. Classes generally contain multiple
methods. Methods define the behavior of the class. However, the HelloWorld class
has only one method Main.
Main method is the entry point into your application.
Sample program
Arithmetic operator
Comparison operator
Output
Conditional operator(And)
Conditional operator(OR)
Ternary use
Example:
for (int a = 10; a < 20; a = a + 1)
{
Statements(s);
}
Constructor
It is a special type of method which has a same name as of a class
name generally it is used to initialize a value for a variable.
Uses
Constructors enable the programmer to set default values,and
write code that is flexible and easy to read.
Rules
Constructor should have a same name has
of a class name.
Constructor will not have a return type.
Destructor
It is a special type of method which has a
same name as a class name. Which will
precide with(~)tilled symbol.
Uses:
It is used to deallocate the memory of the
variable.
Output