Vous êtes sur la page 1sur 45

XIT702 C# AND .

NET FRAMEWORK

Introducing C#

What is C#?
C# Pronounced as C sharp Computer programming Language developed by Microsoft Corporation C# is a fully object-oriented language like Java First Component-oriented language Simple, efficient, productive and type-safe language derived from the popular C and C++ language Suitable for developing Web-Based applications

What is C#?
Major highlights of C#: It is a brand new language derived from the C / C++ family It simplifies and modernizes C++ It is the only component-oriented language It is short, lean and modern language It combines the best features of many commonly used languages: the productivity of Visual Basic, the power of C++ and the elegance of Java

What is C#?
Major highlights of C#: Cond It is basically object-oriented and web enabled It has a lean and consistent syntax It embodies todays concern for simplicity and productivity and robustness It will become the language of choice for .NET programming Major parts of .NET Framework are actually coded in C#

Why C#?
The history of major languages developed during the last three decades

1967 BCPL 1970


1972 1983

C C++

Dennis Ritchie Bjarne Stroustrup

1987 ANSI C ANSI Committee 1991 1995

Oak Java

James Gostling Sun MicroSystems

1996 ANSI C++ ANSI Committee 2000

C#

Microsoft

Why C#?
C and C++ have been most popular languages for the past two decades These languages suffer from a number of shortcomings are the following: The high complexity of the language Their long cycle time They are not truly Object-oriented They are not suitable for working with new web technologies They have poor type-safety They are prone (prone - lying face downward) to costly programming errors

Why C#?
They do not support versioning They are prone to memory leakages Their low productivity Their poor interoperability with the existing systems They are weak in consistency Their poor support for component programming

Why C#?
Java is truly object-oriented Java has been widely used for web applications for the past five years Unfortunately , Java has not retained some powerful C++ features such as operator overloading To overcome these disadvantages of C,C+ + and Java Microsoft decided to design a new language called C#. C# is simple and modern language

Evolution of C#
We have a number of limitations in using the WWW over the internet We can see only one site at a time The site has to be authored to our hardware environment The information we get is basically read-only We cannot compare dynamically similar information stored in different sites The internet is a collection of many information islands that do not co-operate with each other

Evolution of C#
To overcome these limitations Microsoft wants to develop a new software platform called .NET .NET is simply the Microsofts vision of software as a service Microsoft introduced C# as a de facto (dominant position) language of the .NET platform C# has been particularly designed to build software components for .NET and it supports key features of .NET natively

Evolution of C#
They are fairly tightly tied together C# compiler is embedded into .NET
.NET Platform .NET Framework
C#
C# inside the .NET

Like Java, C# is descendant of C++ C++ is a descendant of C ( See fig. Evolution of C# language)

Evolution of C#
C
Concept Object Orientation Concept

C++
Power Component Orientation

Java

Elegance

C#

Productivity

VB

Evolution of C# language

Evolution of C#
C# borrows Javas features such as grouping of classes, interfaces and implementation together in one file so that programmers can edit the code more easily C# also handles objects using references, the same way as Java C# uses VBs approach to form design

1. 2. 3. 4. 5. 6. 7. 8. 9.

Characteristics of C#
Simple Consistent Modern Object-oriented Type-safe Versionable Compatible Interoperable Flexible

Characteristics of C#
1. Simple
C# simplifies C++ by eliminating operators such as >,:: and pointers It treats integer and Boolean are different data types Use = in place of = = in if statements

1. Consistent
C# supports an unified type system which eliminates the problem of varying ranges of integer types All types are treated as objects Developers can extend the type system simply and easily

Characteristics of C#
3. Modern
C# is called a modern language due to a number of features it supports Automatic garbage collection Rich intrinsic model for error handling Decimal data type for financial applications Modern approach to debugging and Robust security model

Characteristics of C#
4. Object-oriented
C# is truly object-oriented It supports Encapsulation Inheritance Polymorphism The entire C# class model is built on top of the Virtual Object System (VOS) of the .NET Framework In C#, everything is an object There are no more global functions, variables and constants

5. Type-safe

Characteristics of C#
Type safety promotes robust programs C# incorporates a number of type-safe measures they are All dynamically allocated objects and arrays are initialized Use of any uninitialized variables produces an error message by the compiler Access to arrays are range-checked and warned if it goes out-of-bounds C# does not permit unsafe casts

Characteristics of C#

C# enforces overflow checking in arithmetic

operations Reference parameters that are passed are typesafe C# supports automatic garbage collection

6. Versionable
Making new versions of software modules work with the existing applications is knows as versioning New and override keywords are support new versioning

Characteristics of C#
7. Compatible
C# enforces the .NET common language specifications and therefore allows inter-operation with other .NET languages C# provides support for transparent access to standard COM and OLE Automation C# also permits interoperation with C-style APIs

8. Flexible
C# does not support pointers

Characteristics of C#
We may declare certain classes and methods as unsafe and then use pointers to manipulate them However, these codes will not be type-safe

9. Inter-operability
C# provides support for using COM objects No matter what language was used to author them

Applications of C#
Variety of applications that are supported by the .NET platform: Console applications Windows applications Developing Windows controls Developing ASP.NET projects Creating web controls Providing web services Developing .NET component library

How does C# differ from C++?


C# was derived from C++ C# shares major parts of syntax with C++ The C# designers introduced a few changes in the syntax of C++ and removed a few features

How does C# differ from C++?


Changes introduced in C#: Does Does not 1. C# compiles straight separate class definition from source code to from implementation executable code, with no object files 2. Classes are defined and Use a semicolon at the implemented in the sameend of the class definition place and therefore there is no need for header files

How does C# differ from C++?


Changes introduced in C#: Does Does not
3. The first character of the main support #include statement function capitalized ( note that using is not the public static void Main(). same as #include) The main must return either int using System; or void type value

4. All data types in C# are inherited from the object super class and therefore they are objects

Support pointer types for manipulating data.

Changes introduced in C#: Does Does not 4. Pointer codes are consider Support the labeled break as a unsafe code 5. All the basic value types Support default arguments will have the same size on any system. This is not the case in C or C++. Thus C# is more suitable for writing distributed applications

How does C# differ from C++?

How does C# differ from C++?


Changes introduced in C#: Does Does not 6. Data types belong to either Provide any defaults for value types ( which are Constructors created in a stack) or Reference types ( Which are created in a heap) 7. C# checks for uninitialized Access static members via variables and gives error an object messages at compile time

How does C# differ from C++?


Changes introduced in C#: Does Does not 8. structs are value types 9. supports a string type. Manipulation of strings are easy 10. Declares null as a keyword and considers it as an intrinsic (built-in) value Support multiple code Inheritance

How does C# differ from C++?


Changes introduced in C#: Does 11. Variable scope rules in C# are more restrictive. In C#, duplicating the same name within a routine is illegal, even if it is in a separate code block 12. Permits declaration of variables between goto and Label 13. Create objects using new keyword

How does C# differ from C++?


Changes introduced in C#: Does 14. Arrays are classes and they have built-in functionality for operations such as sorting, searching and reversing 15. Arrays are declared differently and behave very differently compared to C++ arrays 16. Provides special syntax to initialize arrays efficiently 17. Arrays are always reference types rather than value types

How does C# differ from C++?


Changes introduced in C#: Does 18. Expressions in if and while statements can use assignment operator (=) instead of equality operator (= =) 19. Support four iteration statements rather than three in C+ +. The fourth one is the foreach statement 20. Switch can also be used on string values 21. Set of operators that can be overloaded in C# is smaller compared to C++

How does C# differ from C++?


Changes introduced in C#: Does 22. Can check overflow of arithmetic operators and conversions using checked and unchecked keywords 23. Variable method parameters are handled differently in C# 24. In exception handling, we cannot throw any type in C# 25. Requires ordering of catch blocks correctly 26. Catch () is replaced by simple catch in C#

How does C# differ from C++?


Changes introduced in C#: Does 27. Destructors in C# behave differently than in C++ 28. Casting in C# is much safer than in C++ 29. When overriding a virtual method, we must use the override keyword

How does C# differ from C++?


Changes introduced in C#: Does 30. Abstract methods in C# are similar to virtual functions in C++, but C# abstract methods cannot have implementations 31. Command-line parameters array behave differently in C#

How does C# differ from C++?


C++ features dropped
The following C++ features are missing from C# 1. Macros 2. Multiple inheritance 3. Templets 4. Pointers 5. Global variables 6. Typedef statement 7. Default arguments 8. Constant member functions or parameters 9. Forward declaration of classes

How does C# differ from C++?


Enhancements to C++
C# modernizes C++ by adding the following new features: 1. Automatic garbage collection 2. Versioning support 3. Strict type-safety 4. Properties to access data members 5. Delegates and events 6. Boxing and unboxing 7. Web services

How does C# differ from Java?


Like C#, Java was also derived from C++ C# was developed by Microsoft C# is an alternative to Java for web programming C# borrowed many good features from Java But number of differences between C# and Java: 1. C# uses .NET runtime that is similar to Java runtime 2. C# has more primitive data types 3. Unlike Java, all C# data types are objects

How does C# differ from Java?


4. Arrays are declared differently in C# 5. C# classes are quite similar to Java classes 6. Few important differences in C# from Java are constants, base classes and constructors, static constructors, versioning, accessibility of members etc.., 7. C# uses const to declare a class constant but Java uses static final 8. C# supports the struct type and Java dose not

How does C# differ from Java?


9. In Java, class members are virtual by default and a method having the same name in a derived class overrides the base class member 10.In C#, the base class member is used virtual keyword and the derived class member is used override keyword 11.C# provides better versioning support than Java 12.C# provides static constructors for initialization 13.C# provides built-in delegates and events

How does C# differ from Java?


14.In Java, parameters are always passed by value. In C#, parameters to be passed by reference by using the ref keyword 15.C# adds internal, a new accessibility modifier. Members can be accessed from other classes within the same project, but not from outside project 16.Java does not directly support enumerations 17.Java does not have any equivalent to C# indexers

How does C# differ from Java?


18. Both Java and C# support interfaces 19. Java supports only the integer expression in the switch statement 20. C# supports either an integer or string expression in the switch statement 21. Catch block should be ordered correctly in C# 22. C# checks overflows using checked statements 23. C# uses is operator instead of instanceof operator in Java

How does C# differ from Java?


24. There is no labeled break statement in C# 25. The goto is used instead of break statement

XIT702 C# AND .NET FRAMEWORK

Understanding .NET

The C# Environment
The .NET Strategy
Three key approaches
Microsoft .NET strategy

Microsoft .NET Platform

Microsoft .NET Products & Services

Third-Party .NET services

Microsoft .NET Strategy

Vous aimerez peut-être aussi