C# EMILEE KING

advertisement
C#
EMILEE KING
HISTORY OF C#
• In the late 1990’s Microsoft recognized the need to be able to develop
applications that can run on multiple operating system platforms.
• This led to the creation of the .NET Framework.
• In the Pre-release stage the .NET Framework used multiple languages
HISTORY OF C#
• C++, Visual, and ASP all of which were used for different parts of the
framework and were not interchangeable.
• Anders Hejlsberg and his team wanted to be able to offer a more unified
solution for this framework.
• Modern concepts, such as object orientation, type safety, and garbage
collection and structured exception handling directly into the platform.
HISTORY OF C#
• COOL: C-Like Object Oriented Language
• C++ was seen as an increment of C
• C++++ so C# can be seen as an increment of C++
• The name for C# was changed and the language was publicly announced
alongside the .NET project at the July 2000 Professional Developers
Conference.
NAMES
• Case-Sensitive: : sumOfAverages, SumOfAverages, SUMOFAVERAGES
• PascalCasing for class names and method names
• camelCasing for method arguments and local variables
• Use noun or noun phrases to name a class
• Avoid using SCREAMINGCAPS for constants or readonly variables
KEYWORDS
• C# has two different types of keywords, contextual keywords and reserved
keywords.
• Contextual keywords are only treated as keywords in certain situations.
• Reserved keywords are treated like keywords in all situations.
• Both are always lowercase
BINDINGS
• Static and Dynamic
• C# defaults to static
• Allows dynamic binding for certain operations:
•
•
•
•
Member access
Element access
Method invocation
Assignment operators
DATA TYPES: VALUE TYPES
• Instances of value types are allocated on the stack.
• Primitive Data Types: Int, Float, Char.
• User Defined Structures (Structs)
• Cannot derive from each other
• Cannot have explicit constructors
• Bound to their variables, so inefficient for sharing data between classes
DATA TYPES: REFERENCE TYPES
• Instances of a reference type are allocated in the heap.
• Strings, Arrays, Class types, Delegates
• Contains the address of a location in memory where the data referred to by
that variable is stored
• When the variable is not referencing any object the variable will be null.
• Will not be destroyed until C#’s garbage collection system determines that it
is no longer needed.
GENERICS
• C# is a strongly typed language
• Generics were introduced in Version 2.0 of .NET Framework
• Combine reusability, type safety and efficiency in a way that their nongeneric counterparts cannot
• Avoids computational cost of boxing and unboxing.
• Allows the compiler to do type-checking
ARRAYS
• One dimension
• Multidimensional
• Array of Arrays (Jagged Arrays)
EXPRESSIONS AND ASSIGNMENT STATEMENTS
•
•
•
•
•
•
•
•
•
Left to Right
Primary: x.y, f(x), a[x], x++, x-Unary: +, -, !, ~, ++x, --x, (T)x
PEMDAS
Shift: <<, >>
Relational and type testing: <, >, <=, >=, is, as
Equality: ==, !=
Logical Expressions: &, ^, |
Conditional Expressions &&, ||, ?:
CONDITIONAL STATEMENTS
• If-else
• Else-if
• Switch Statements
ITERATIVE STATEMENTS
• While
• Do While
• For Loop
• For Each Loop
METHODS
• Methods define how a class should behave
• Structs can have methods
• Can not be nested
• Can be passed as parameters called Delegates
• Can have any type including user defined and void
CLASSES
• Reference Types
• Can be nested
• Support inheritance
• Used for data that might be modified after the class is created
• Can implement interfaces
STRUCTS
• Value type
• Do not support inheritance
• Used for data that will not be modified after the struct is created
• Can implement interfaces
• Unlike C++ structs, C# structs are light weight classes
OPERATOR OVERLOADING
• Unary, binary, and comparison operators can be overloaded
• Cast operators and array indexing cannot be overloaded
• Conversion operators can be defined for cast operators
• New indexers can be defined for array indexing
ABSTRACT DATA TYPES AND ENCAPSULATION
CONSTRUCTS
• Similar to C++ and Java
• C# allows destructors, although rarely used due to garbage collection
• Two new access modifiers: Internal and Protected Internal
• Properties can implement getters and setters without explicit method calls
SUPPORT FOR OBJECT ORIENTED PROGRAMMING
• Encapsulation
• Inheritance
• Polymorphism
• Dynamic Binding
• Nested classes
• Classes and Structs can implement interfaces
CONCURRENCY
• Based largely on Java
• Supports actor and server threads
• Built in classes for thread synchronization
• Interlocked class
• Monitor class
EXCEPTION HANDLING
• Large amount of predefined exception classes
• Allows user defined exceptions
• Try block is where potential problem code is located
• Catch catches an exception (also known as exception filter)
• Finally block executes code regardless of how try block is exited
EVENT HANDLING
• Static and Dynamic
• Static: only in effect in the class of the events that they handle
• Dynamic: activated and deactivated throughout the entire program in
response to their conditional programming logic.
• Both use two parameters that are always of type object and EventArgs
READIBILITY
• Very organized
• Regions
• Intuitive
• User defined structs and enumerations allows programmers to clearly label
what their program is doing
WRITABILITY
• Many different ways to write code and get the same effect
• Intuitive
• Allows for user defined structs and enumerations
RELIABILITY
• Strongly typed language
• Strict with type checking
• Large amount of built in exception handling
• Allows for user defined exception handling
• Unsafe code has to be explicitly marked and enabled in the compiler
• Large amount of documentation online
COST
• Visual Studio
• Commercial Version
• Training
• Large amount of documentation online by Microsoft
• Updates
Download