Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
What is C# Why use C# Evolution of C# Characteristics of C# Difference between C# and C++ Difference between C# and Java Variables Data Types Decision Making Looping
What is C#
What is C#?
C# (pronounced as C Sharp) is a computer
programming language developed by Microsoft Corporation, USA in June 2000. C# is a object-oriented language C# has been designed to support the key features of .NET Framework. C# is a modern language suitable for developing Web-based applications.
WHY Use c#
Martin Richards
Ken Thompson
1967
BCPL
1970
Dennis Ritche
Bjarne Stroustrup
ANSI Committee
James Gostling
Sun Microsystems
ANSI Committee
Microsoft
EVOLUTION OF c#
Evolution of C#
To overcome the number of limitations in using the WWW over the Internet, Microsoft Chairman Bill Gates wanted to develop a software platform which would enable users to get information anytime and anywhere, using a natural interface. The platform must be a collection of readily available Web Services that can be distributed and accessed via standard internet protocols. The outcome was a new generation platform called .NET Microsoft introduced C# as the language of the .NET platform. C# has been particularly designed to build software components for .NET and it supports the key features of .NET.
characteristics of c#
Characteristics of C#
Simple
C# simplifies C++ by eliminating irksome operators such as ->,:: and pointers. Flexible C# does not support pointers, but we may declare certain classes and methods as unsafe and then use pointers to manipulate them. Modern It supports automatic garbage collection, modern approach to debugging, robust security model
Characteristics of C#
Object-Oriented
It supports Encapsulation, Inheritance, Polymorphism Type-Safe Type-Safety promotes robust programs. It supports automatic garbage collection. It enforces overflow checking in arithmetic operations Versionable Making new versions of software modules work with the existing applications is known as versioning
first character of Main() function is Capitalized. The Main() must return either int or void type value C# does not support #include statement In C#, data types belong to either values types or reference types In C#, switch can also be used on string values C# can check overflow of arithmetic operations and conversions using checked and unchecked keywords
have built-in functionality for operations such as searching, sorting and reversing. C# does not support pointer types for manipulating data. However they are used in what is know as unsafe code. C# does not provide any defaults for constructors C++ allows multiple inheritance while C# does not.
while C# uses Const C# supports the struct type and Java does not Java does not provide for Operator Overloading Java does not have any equivalent to C# indexers In C#, switch can also be used on strings C# has the ability to alias namespaces
over collections and array type data C# checks overflows using checked statements There is no labeled break statement in C#. The goto is used to achieved this C# has support for output parameters, aiding in the return of multiple values, a feature shared by C++ and SQL
Variables
Variables
A variable is an identifier that denotes a storage
location used to store a data value. A variable may take different values different values at different times during the execution the execution of the program. There are some rules for declaring variable names: 1. They must not begin with a digit 2. Uppercase and lowercase are distinct 3. It should not be a keyword 4. White space is not allowed 5. Variable names can be of any length
Data Types
Data Types
Every variable in C# has a data type. Data types
specify the size and type of values that can be stored. C# is rich in its data types. In C#, variables are the names of storage locations. After designing suitable variable names, we must declare them to the compiler. Declaration does three things: 1. It tells the compiler what the variable name is 2. It specifies what type of data it can hold 3. The place of declaration decides the scope of the variable
Data Types
The types in C# are divided into two types:
Value types and Reference types differ in two characteristics: 1. Where they are stored in the memory 2. How they behave in context of assignment statements
C# Data Types
Value Types
Pointer s
Reference Types
Enumeration s Structures
Objects Strings
Simple Types
Boolea n Types
Numeri c Types
Characte r Types
Integral Types
Decima l Types
Signed Types
Unsigne d Types
Decision Making
Decision Making
IF Statement:
It tests a particular condition. Syntax if(condition checking expression) { Statement for true condition; }
If-else Statement: the else part gets executed if the
Control Constructs
if(condition checking expression) { statement for true condition; } else { statement for false condition; }
If else-If statement:
Control Constructs
if(condition expression) { statement for true condition; } else if(condition expression) { statement for true condition of else-if ; } else if(condition expression) { statement for true condition of else-if ; } else { statement for false condition of all if; } Level1
Level2
Level3
Control Constructs
Nested If Statement: A nested if is an if that has another if in its ifs body or elses
body or both.
Syntax: if(condition expression) { if(expression){ Statement1;} else{ statement2;} } else{ if(expression){ Statement1;} else{ statement2;} }
Iteration/Loop Statement
Loop: used for repetition of same task.
Loop consists of three part: 1. Initialization exp: used to began loop , it executed only once. 2. Test/Condition exp: its truth value decides whether the loop body will be executed or not. 3. Update exp: It change the value of loop variable. It executed at the end of loop after the loop-body is executed. 4. The Body-of -the-loop: contains statement of loop
Types of Loop
for Loop while- Loop do-while Loop For- Loop: It initialize first, then test the condition, then execute statement from body of loop , and then execute update expression. Syntax: for(Initialization exp; Test exp; Update exp) { Body of loop Statements }
Nested-for-Loop
Syntax: for(Initialization exp; Test exp; Update exp) { Body of outer for loop for(Initialization exp; Test exp; Update exp) { Body of inner for loop Statements } }
While Loop
It tests the condition , then execute the statement
Do-while Loop
It executes the statements then executes update
expression, and then test the condition. It executes statements for one time false condition. Syntax: do { Statements Body of Loop Update expression } while(test expression);