20 Intro To Csharp
20 Intro To Csharp
University of Virginia
C# Genealogy
Elementary
Procedural
Advanced
Procedural
Special
Procedural
Object
Oriented
Advanced
Object
Oriented
Eiffel
Fortran
Algol 68
C++
C#
Cobol
PL/I
Pascal
Ada 95
Java
Ada 83
University of Virginia
C# And .Net
Languages like C# are not isolated entities
They interoperate in two ways:
University of Virginia
Declarations
Expressions
Assignment and control statements
Classes
Functions
Polymorphism
University of Virginia
University of Virginia
Namespaces
Namespace CS415
Class A
Class B
Class C
Namespace CS340
Class A
Class B
CS415.A
Class C
CS340.A
CSharp ( John Knight
University of Virginia
Type System
bool Equals
int GetHashCode
Type GetType
String ToString
University of Virginia
Types Of Types
Value types and reference types
Value types:
Reference types:
University of Virginia
Stack
myInt
42
myStr
address
Hello World
address
Circle object
Be careful
with
deallocation
of the space
University of Virginia
myInt = 42;
o
= myInt;
ymInt = (int)o;
Heap
Stack
myInt
Boxed
myInt
object o
42
42
10
University of Virginia
Type
safety:
11
University of Virginia
Memory Layout
Heap
Stack
f calls g, g calls h, h calls k
f()
P*
Pointers
Garbage Collector
12
University of Virginia
C# Memory Management
Static vs. dynamic
Dynamic storagestack and heap
Stack (Dynamic):
Heap (Dynamic)
13
University of Virginia
C# Memory Management
Allocation using new
Deallocation by Garbage Collection
Garbage collection:
14
University of Virginia
Pros:
Cons:
15
University of Virginia
Some Specifics of C#
E.g., GC.collect()
16
Object
cannot be
moved
University of Virginia
Traditional Compilation
Source
Program
Compiler
Relocatable
Object
Program
Linkage
Editor
Object Code
Static
Libraries
Linking
Not
Relocatable
Relocatable
Object
Program
Machine
Instructions For
Specific Target
Loader
17
Dynamic
Linking
Binary
Program
University of Virginia
Compiler
Microsoft
Intermediate
Language (MSIL)
Program
Machine
Instructions
For Multiple
Targets
TARGET
TARGET
Interpreter
18
University of Virginia
Concurrency
Threads vs. processes/tasks
C# supports threads
What exactly
are the
problems
here?
Thread
Who is
running
and when?
Communication
Thread
Thread
Thread
Data
CSharp ( John Knight
19
University of Virginia
C# Threads
System.Threading namespace
Facilities include:
Synchronization:
Monitors
Semphores (mutex class)
Lockserialization of statement block
20
University of Virginia
Exceptions
21
University of Virginia
22
University of Virginia