2. What is C#?
It is a computer-programming language developed by Microsoft
Corporation, USA.
It is fully object-oriented language.
Suitable for developing Web-based applications
Designed for developing robust, reliable & durable components
to handle real-world applications.
3. Highlights of C#
Derived from C/C++ family.
It simplifies & modernizes C++.
It is only component oriented language available today.
It is a language designed for the .NET Framework.
It is a concise, lean & modern language.
It combines the best features of many commonly used languages: the
productivity of VB, the power of C++, & the elegance of Java.
It is intrinsically object-oriented & web-enabled.
It has a lean & consistent syntax.
It is simple, robust & productive.
Major parts of .NET Framework are actually coded in C#.
4. Why C# ?????
The primary motivation while developing any language is the
concern that it able to handle the increasing complexity of programs
that are robust, durable & maintainable.
The history of major languages developed is as follows:
BPCL B
C
C++
ANSI C
Oak
Java
ANSI C++
C#
1967 1970
1972
1983
1987
1991
1995
1996
2000
Dennis Ritchie
Bjarne Stroustrup
ANSI Committee
James Gostling
Sun MicroSystems
ANSI Committe
Microsoft
Martin Richards Ken Thompson
5. Continue….
C & C++ languages suffer from a
number of shortcomings in
meeting World Wide Web
requirements & standards.
Some are as follows:
1. The high complexity of language
2. They are not truly object oriented
3. They have poor type safety
4. They are not suitable for working
with new web technologies.
5. They do not support versioning
6. They are weak in consistency
7. Their poor compatibility with the
existing systems
VB, a language promoted by
Microsoft for overcoming these
problems, is not truly object-
oriented and becomes
increasingly difficult to use when
systems become large.
Java which is truly object-
oriented has not retained some
powerful C++ features such as
operator overloading.
Java also lacks inter-operability
with code developed in other
languages.
Microsoft therefore decided to
design a new language.
The result is C#, a simple &
modern language that directly
addresses the needs of
component-based software
development.
6. C# is a descendant of C++ which in turn is a
descendant of C as illustrated below:
C
C++
Java C# VB
Concept
ProductivityElegance
Concept
Component
Orientation
Object
Orentation
Power
7. Characteristics of C#
Simple
C# simplifies C++ by eliminating irksome operators such as ->,
::, and pointers.
C# treats integers & Boolean data types as entirely different
types.
Consistent
C# supports an unified type system which eliminates the
problem of varying ranges of integer types.
All types are treated as objects.
Modern
C# is called modern language because it supports:
Automatic garbage collection
Rich intrinsic model for error handling
Decimal data types for financial applications
Modern approach to debugging
Robust security model
8. Continue….
Object-Oriented
C# is truly object-oriented. It supports:
Encapsulation
Inheritance
Polymorphism
Type-Safe
Type safety promotes robust programs.
C# incorporates number of type-safe measures:
All dynamically allocated objects & arrays are initialized to
zero
Use of any uninitialized variables produces an error message
by the compiler
C# supports automatic garbage collection
Version able
Making new versions of software modules work with the
existing applications is known as versioning
C# provides support for versioning with the help of new &
override keywords.
9. Compatible
C# enforces the .NET common
language specifications & therefore
allows inter-operation with other
.NET languages
Interoperable
C# provides support for using COM
objects, no matter what language
was used to author them.
Flexible
We may declare certain classes &
methods as ‘unsafe’ and then use
pointers to manipulate them.
Continue…
10. How Does C# differs from Java ?
1. C# has more primitive data types
2. Arrays are declared differently in C#
3. C# supports struct type & Java does not
4. Java does not provide for operator overloading
5. C# provides for better versioning support than Java
6. C# provides static constructors for initialization
7. Java does not directly support enumerations
8. C# uses is operator instead of instanceof operator in Java
9. C# checks overflows uses checked statements
10. There is no labeled break statement in C#. The goto statement is
used to achieve this.
11. In Java, the switch statement can have only integer expression,
while C# supports either an integer or string expressions
11. A Simple C# Program
class SampleOne
{
public static void Main()
{
System.Console.WriteLine(“C# is sharper than C++”);
}
}
Executing the program
Save the above file with SampleOne.cs name
Compile as : csc SampleOne.cs
C# compiler compiles your code and create an executable file by
name
SampleOne.exe
For executing the program, simply type in the name of the
executable file at the command prompt.
12. NAMESPACES
System.Console.WriteLine();
Here System is a namespace in which the Console class is located.
This class can be accessed using the dot operator.
C# supports using directive that can be used to import the
namespace System into the program.
using System;
class SampleTwo
{
public static void Main()
{
Console.WriteLine(“Hello World!!!”);
}
}
13. Providing Interactive Input
using System;
class SampleEight
{
public static void Main(string[] args)
{
Console.Write(“Enter Your Name”);
string name = Console.ReadLine();
Console.WriteLine(“Hello ”+name);
}
}