SlideShare a Scribd company logo
University of VirginiaCSharp (© John Knight 2005) 1
What’s New In C#
University of VirginiaCSharp (© John Knight 2005) 2
C# Genealogy
Fortran Algol 68 C C++ C#
Cobol
Eiffel
JavaAda 95PL/I Pascal
Elementary
Procedural
Advanced
Procedural
Special
Procedural
Object
Oriented
Advanced
Object
Oriented
Ada 83
University of VirginiaCSharp (© John Knight 2005) 3
C# And .Net
 Languages like C# are not isolated entities
 They interoperate in two ways:
 By being part of a system written in more than one
language
 By accessing services and operating on a distributed
environment
 Requires support from run time:
 .Net and the Common Language Runtime
 .Net is many things, in particular binary object
access
 C# interoperates with .Net
University of VirginiaCSharp (© John Knight 2005) 4
The Simple Stuff
 Most of C# is pretty similar to languages you are
used to:
 Declarations
 Expressions
 Assignment and control statements
 Other elements are quite similar:
 Classes
 Functions
 Polymorphism
University of VirginiaCSharp (© John Knight 2005) 5
Major Topics To Discuss
 Identifier scope system—namespaces
 Type system
 Memory system and pointers
 Execution time environment
 Threads
 Exceptions
 Interfaces
University of VirginiaCSharp (© John Knight 2005) 6
Namespaces
Namespace CS415
Class A
Class B
Class C
 Permits isolation of names
 Can be nested
 Access via fully qualified
names
Namespace CS340
Class A
Class B
Class C
CS415.A…
CS340.A…
University of VirginiaCSharp (© John Knight 2005) 7
Type System
 Type should be consistent:
 Predefined and user-defined
 All C# types derive from System.Object
 Single rooted hierarchy
 Provides four standard methods:
 bool Equals
 int GetHashCode
 Type GetType
 String ToString
These don’t necessarily
mean what you think
Same object (ref) or same value (val)
Retrieve object type (reflection)
Retrieve object type (default)
University of VirginiaCSharp (© John Knight 2005) 8
Types Of Types
 Value types and reference types
 Value types:
 Program variables have a value
 Space allocated on stack
 Reference types:
 Program variable is just a reference
 Allocated space on stack
 Reference is a “type-safe” pointer
 Data space allocated on heap
University of VirginiaCSharp (© John Knight 2005) 9
Value vs. Reference
 Note the “special” status of primitive types
System.Int32 myInt = 42;
System.String myStr = “Hello World”;
Circle c;
c = new Circle(...);
42
address “Hello World”
Stack Heap
myStr
myInt
address Circle objectc
Be careful
with
deallocation
of the space
University of VirginiaCSharp (© John Knight 2005) 10
Boxing And Unboxing
 Conversion between value variable and
reference variable
System.Int32 myInt = 42;
object o = myInt;
int ymInt = (int)o;
42
o 42
Stack Heap
Boxed
myInt
object o
myInt
University of VirginiaCSharp (© John Knight 2005) 11
The Role Of A Type System
 What do we need from a type system?
 Types across languages:
 Consistency
 Compatibility
 Type safety:
 Checking for meaningful statements
 Add “speed” to “distance”?
 C# vs Ada
University of VirginiaCSharp (© John Knight 2005) 12
Memory Layout
Stack Heap
Garbage CollectorFunction Call & Return
Pointers
f() g() h() k()
f calls g, g calls h, h calls k
P*
University of VirginiaCSharp (© John Knight 2005) 13
C# Memory Management
 Static vs. dynamic
 Dynamic storage—stack and heap
 Stack (Dynamic):
 Managed algorithmically by implementation of
function calls
 Heap (Dynamic)
 Mostly managed by system
 Provision for management by programmer
University of VirginiaCSharp (© John Knight 2005) 14
C# Memory Management
 Allocation using new
 Deallocation by Garbage Collection
 Garbage collection:
 Tracks objects that are accessible
 Frees storage associated with objects that are
inaccessible
 Garbage collector is a system provided service that
runs periodically
 Deals with fragmentation
University of VirginiaCSharp (© John Knight 2005) 15
Garbage Collector Pros & Cons
 Pros:
 Programmer does not have to implement
 Memory management done right
 Cons:
 No guarantee when it runs, hence no control
 Takes processor resources
 Does not delete storage if it is still reachable even if
you don’t want it…
 Memory leaks can (and do) still occur
University of VirginiaCSharp (© John Knight 2005) 16
Some Specifics of C#
 Object destruction via Object.Finalize:
 Inherited from Object type
 Override to destroy object as desired
 Garbage collector available via GC class:
 Runs via separate thread
 Various methods available for access
 E.g., GC.collect()
 Pointers—yes, they are provided:
 Syntax like C++, code marked unsafe
 Objects managed by GC or user—pinned
Object
cannot be
moved
University of VirginiaCSharp (© John Knight 2005) 17
Traditional Compilation
Source
Program
Compiler
Object
Program
Linkage
Editor
Object
Program
Loader
Binary
Program
Machine
Instructions For
Specific Target
Object Code
Libraries
Relocatable
Relocatable
Not
Relocatable
Dynamic
Linking
Static
Linking
University of VirginiaCSharp (© John Knight 2005) 18
More Flexible Compilation
Source
Program
Compiler
Microsoft
Intermediate
Language (MSIL)
Program
TARGET
Run-time Support System
Machine
Instructions
For Multiple
Targets
TARGET
Run-time Support System
Interpreter Just-in-Time (JiT) Comp
University of VirginiaCSharp (© John Knight 2005) 19
Concurrency
 Threads vs. processes/tasks
 C# supports threads
Thread Thread Thread
Thread
Data
Communication
Who is
running
and when?
What exactly
are the
problems
here?
University of VirginiaCSharp (© John Knight 2005) 20
C# Threads
 System.Threading namespace
 Facilities include:
 Thread creation, destruction
 Child thread management, e.g. join()
 Thread scheduling, priority, timing
 Synchronization:
 Monitors
 Semphores (mutex class)
 Lock—serialization of statement block
University of VirginiaCSharp (© John Knight 2005) 21
Exceptions
 Why do we need exceptions?
 How should they be made available in programming
languages?
 What benefits do they provide?
 What problems could they cause for us?
 Throw raises an exception
 Catch defines a block that handles the exception
 Etc.
University of VirginiaCSharp (© John Knight 2005) 22
One Thing Is For Sure…
 Exceptions are NOT for dealing with errors
 They are a mechanism for changing the flow of
control from sequential to a branch if certain
conditions exist
 They always indicate expected circumstances.
Otherwise they could not possibly be
generated

More Related Content

What's hot

ITK Tutorial Presentation Slides-949
ITK Tutorial Presentation Slides-949ITK Tutorial Presentation Slides-949
ITK Tutorial Presentation Slides-949
Kitware Kitware
 
Encoding Object-oriented Datatypes in HOL: Extensible Records Revisited
Encoding Object-oriented Datatypes in HOL: Extensible Records RevisitedEncoding Object-oriented Datatypes in HOL: Extensible Records Revisited
Encoding Object-oriented Datatypes in HOL: Extensible Records Revisited
Achim D. Brucker
 
Post-graduate course: Object technology: Implementation of object-oriented pr...
Post-graduate course: Object technology: Implementation of object-oriented pr...Post-graduate course: Object technology: Implementation of object-oriented pr...
Post-graduate course: Object technology: Implementation of object-oriented pr...
Baltasar García Perez-Schofield
 
CLTL: Description of web services and sofware. Nijmegen 2013
CLTL: Description of web services and sofware. Nijmegen 2013CLTL: Description of web services and sofware. Nijmegen 2013
CLTL: Description of web services and sofware. Nijmegen 2013
Rubén Izquierdo Beviá
 
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression TreesExploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
rasmuskl
 
Metamodeling vs Metaprogramming, A Case Study on Developing Client Libraries ...
Metamodeling vs Metaprogramming, A Case Study on Developing Client Libraries ...Metamodeling vs Metaprogramming, A Case Study on Developing Client Libraries ...
Metamodeling vs Metaprogramming, A Case Study on Developing Client Libraries ...
Markus Scheidgen
 
A Lightweight Formal Encoding for a Constraint Language DSML Component
A Lightweight Formal Encoding for a Constraint Language DSML ComponentA Lightweight Formal Encoding for a Constraint Language DSML Component
A Lightweight Formal Encoding for a Constraint Language DSML Component
Marc Pantel
 
Summer training vhdl
Summer training vhdlSummer training vhdl
Summer training vhdl
Arshit Rai
 
Road to Dynamic LINQ - Part 2
 Road to Dynamic LINQ - Part 2 Road to Dynamic LINQ - Part 2
Road to Dynamic LINQ - Part 2
Axilis
 
Migrating from Objective-C to Swift
Migrating from Objective-C to SwiftMigrating from Objective-C to Swift
Migrating from Objective-C to Swift
Dominique Stranz
 
Road to Dynamic LINQ Part 1
Road to Dynamic LINQ Part 1Road to Dynamic LINQ Part 1
Road to Dynamic LINQ Part 1
Axilis
 
Model-based Analysis of Large Scale Software Repositories
Model-based Analysis of Large Scale Software RepositoriesModel-based Analysis of Large Scale Software Repositories
Model-based Analysis of Large Scale Software Repositories
Markus Scheidgen
 
A Portable Approach for Bidirectional Integration between a Logic and a Stati...
A Portable Approach for Bidirectional Integration between a Logic and a Stati...A Portable Approach for Bidirectional Integration between a Logic and a Stati...
A Portable Approach for Bidirectional Integration between a Logic and a Stati...
Sergio Castro
 
Reverse-Engineering Reusable Language Modules from Legacy DSLs
Reverse-Engineering Reusable Language Modules from Legacy DSLsReverse-Engineering Reusable Language Modules from Legacy DSLs
Reverse-Engineering Reusable Language Modules from Legacy DSLs
David Méndez-Acuña
 
Semantic scaffolds for pseudocode to-code generation (2020)
Semantic scaffolds for pseudocode to-code generation (2020)Semantic scaffolds for pseudocode to-code generation (2020)
Semantic scaffolds for pseudocode to-code generation (2020)
Minhazul Arefin
 
Towards Unified Aspect-Oriented Programming
Towards Unified Aspect-Oriented ProgrammingTowards Unified Aspect-Oriented Programming
Towards Unified Aspect-Oriented Programming
ESUG
 
An Introduction to ANTLR
An Introduction to ANTLRAn Introduction to ANTLR
An Introduction to ANTLR
Morteza Zakeri
 
Software Frameworks for Music Information Retrieval
Software Frameworks for Music Information RetrievalSoftware Frameworks for Music Information Retrieval
Software Frameworks for Music Information Retrieval
Xavier Amatriain
 
Reginf pldi3
Reginf pldi3Reginf pldi3
Reginf pldi3
daniel_yokomizo
 
Generics in dot net
Generics in dot netGenerics in dot net

What's hot (20)

ITK Tutorial Presentation Slides-949
ITK Tutorial Presentation Slides-949ITK Tutorial Presentation Slides-949
ITK Tutorial Presentation Slides-949
 
Encoding Object-oriented Datatypes in HOL: Extensible Records Revisited
Encoding Object-oriented Datatypes in HOL: Extensible Records RevisitedEncoding Object-oriented Datatypes in HOL: Extensible Records Revisited
Encoding Object-oriented Datatypes in HOL: Extensible Records Revisited
 
Post-graduate course: Object technology: Implementation of object-oriented pr...
Post-graduate course: Object technology: Implementation of object-oriented pr...Post-graduate course: Object technology: Implementation of object-oriented pr...
Post-graduate course: Object technology: Implementation of object-oriented pr...
 
CLTL: Description of web services and sofware. Nijmegen 2013
CLTL: Description of web services and sofware. Nijmegen 2013CLTL: Description of web services and sofware. Nijmegen 2013
CLTL: Description of web services and sofware. Nijmegen 2013
 
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression TreesExploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees
 
Metamodeling vs Metaprogramming, A Case Study on Developing Client Libraries ...
Metamodeling vs Metaprogramming, A Case Study on Developing Client Libraries ...Metamodeling vs Metaprogramming, A Case Study on Developing Client Libraries ...
Metamodeling vs Metaprogramming, A Case Study on Developing Client Libraries ...
 
A Lightweight Formal Encoding for a Constraint Language DSML Component
A Lightweight Formal Encoding for a Constraint Language DSML ComponentA Lightweight Formal Encoding for a Constraint Language DSML Component
A Lightweight Formal Encoding for a Constraint Language DSML Component
 
Summer training vhdl
Summer training vhdlSummer training vhdl
Summer training vhdl
 
Road to Dynamic LINQ - Part 2
 Road to Dynamic LINQ - Part 2 Road to Dynamic LINQ - Part 2
Road to Dynamic LINQ - Part 2
 
Migrating from Objective-C to Swift
Migrating from Objective-C to SwiftMigrating from Objective-C to Swift
Migrating from Objective-C to Swift
 
Road to Dynamic LINQ Part 1
Road to Dynamic LINQ Part 1Road to Dynamic LINQ Part 1
Road to Dynamic LINQ Part 1
 
Model-based Analysis of Large Scale Software Repositories
Model-based Analysis of Large Scale Software RepositoriesModel-based Analysis of Large Scale Software Repositories
Model-based Analysis of Large Scale Software Repositories
 
A Portable Approach for Bidirectional Integration between a Logic and a Stati...
A Portable Approach for Bidirectional Integration between a Logic and a Stati...A Portable Approach for Bidirectional Integration between a Logic and a Stati...
A Portable Approach for Bidirectional Integration between a Logic and a Stati...
 
Reverse-Engineering Reusable Language Modules from Legacy DSLs
Reverse-Engineering Reusable Language Modules from Legacy DSLsReverse-Engineering Reusable Language Modules from Legacy DSLs
Reverse-Engineering Reusable Language Modules from Legacy DSLs
 
Semantic scaffolds for pseudocode to-code generation (2020)
Semantic scaffolds for pseudocode to-code generation (2020)Semantic scaffolds for pseudocode to-code generation (2020)
Semantic scaffolds for pseudocode to-code generation (2020)
 
Towards Unified Aspect-Oriented Programming
Towards Unified Aspect-Oriented ProgrammingTowards Unified Aspect-Oriented Programming
Towards Unified Aspect-Oriented Programming
 
An Introduction to ANTLR
An Introduction to ANTLRAn Introduction to ANTLR
An Introduction to ANTLR
 
Software Frameworks for Music Information Retrieval
Software Frameworks for Music Information RetrievalSoftware Frameworks for Music Information Retrieval
Software Frameworks for Music Information Retrieval
 
Reginf pldi3
Reginf pldi3Reginf pldi3
Reginf pldi3
 
Generics in dot net
Generics in dot netGenerics in dot net
Generics in dot net
 

Similar to 20 intro-to-csharp

Introduction to .net FrameWork by QuontraSolutions
Introduction to .net FrameWork by QuontraSolutionsIntroduction to .net FrameWork by QuontraSolutions
Introduction to .net FrameWork by QuontraSolutions
Quontra Solutions
 
Introduction to .NET by QuontraSolutions
Introduction to .NET by QuontraSolutionsIntroduction to .NET by QuontraSolutions
Introduction to .NET by QuontraSolutions
QUONTRASOLUTIONS
 
C#_01_CLROverview.ppt
C#_01_CLROverview.pptC#_01_CLROverview.ppt
C#_01_CLROverview.ppt
MarcEdwards35
 
E sampark with c#.net
E sampark with c#.netE sampark with c#.net
E sampark with c#.net
Abhijeet Singh
 
Typhoon Managed Execution Toolkit
Typhoon Managed Execution ToolkitTyphoon Managed Execution Toolkit
Typhoon Managed Execution Toolkit
Dimitry Snezhkov
 
Csharp dot net
Csharp dot netCsharp dot net
Csharp dot net
Revanth Mca
 
CS4443 - Modern Programming Language - I Lecture (1)
CS4443 - Modern Programming Language - I Lecture (1)CS4443 - Modern Programming Language - I Lecture (1)
CS4443 - Modern Programming Language - I Lecture (1)
Dilawar Khan
 
1.Philosophy of .NET
1.Philosophy of .NET1.Philosophy of .NET
1.Philosophy of .NET
snandagopalan2
 
C sharp
C sharpC sharp
C sharp
Satish Verma
 
.Net Framework Introduction
.Net Framework Introduction.Net Framework Introduction
.Net Framework Introduction
Abhishek Sahu
 
Presentation1
Presentation1Presentation1
Presentation1
kpkcsc
 
Introduction to .NET
Introduction to .NETIntroduction to .NET
Introduction to .NET
Joni
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
shuklagirish
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
shuklagirish
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
shuklagirish
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
shuklagirish
 
NDK Primer (AnDevCon Boston 2014)
NDK Primer (AnDevCon Boston 2014)NDK Primer (AnDevCon Boston 2014)
NDK Primer (AnDevCon Boston 2014)
Ron Munitz
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
YoungSu Son
 
C Course Material0209
C Course Material0209C Course Material0209
C Course Material0209
chameli devi group of institutions
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
arnold 7490
 

Similar to 20 intro-to-csharp (20)

Introduction to .net FrameWork by QuontraSolutions
Introduction to .net FrameWork by QuontraSolutionsIntroduction to .net FrameWork by QuontraSolutions
Introduction to .net FrameWork by QuontraSolutions
 
Introduction to .NET by QuontraSolutions
Introduction to .NET by QuontraSolutionsIntroduction to .NET by QuontraSolutions
Introduction to .NET by QuontraSolutions
 
C#_01_CLROverview.ppt
C#_01_CLROverview.pptC#_01_CLROverview.ppt
C#_01_CLROverview.ppt
 
E sampark with c#.net
E sampark with c#.netE sampark with c#.net
E sampark with c#.net
 
Typhoon Managed Execution Toolkit
Typhoon Managed Execution ToolkitTyphoon Managed Execution Toolkit
Typhoon Managed Execution Toolkit
 
Csharp dot net
Csharp dot netCsharp dot net
Csharp dot net
 
CS4443 - Modern Programming Language - I Lecture (1)
CS4443 - Modern Programming Language - I Lecture (1)CS4443 - Modern Programming Language - I Lecture (1)
CS4443 - Modern Programming Language - I Lecture (1)
 
1.Philosophy of .NET
1.Philosophy of .NET1.Philosophy of .NET
1.Philosophy of .NET
 
C sharp
C sharpC sharp
C sharp
 
.Net Framework Introduction
.Net Framework Introduction.Net Framework Introduction
.Net Framework Introduction
 
Presentation1
Presentation1Presentation1
Presentation1
 
Introduction to .NET
Introduction to .NETIntroduction to .NET
Introduction to .NET
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
NDK Primer (AnDevCon Boston 2014)
NDK Primer (AnDevCon Boston 2014)NDK Primer (AnDevCon Boston 2014)
NDK Primer (AnDevCon Boston 2014)
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
C Course Material0209
C Course Material0209C Course Material0209
C Course Material0209
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
 

Recently uploaded

OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 

Recently uploaded (20)

OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 

20 intro-to-csharp

  • 1. University of VirginiaCSharp (© John Knight 2005) 1 What’s New In C#
  • 2. University of VirginiaCSharp (© John Knight 2005) 2 C# Genealogy Fortran Algol 68 C C++ C# Cobol Eiffel JavaAda 95PL/I Pascal Elementary Procedural Advanced Procedural Special Procedural Object Oriented Advanced Object Oriented Ada 83
  • 3. University of VirginiaCSharp (© John Knight 2005) 3 C# And .Net  Languages like C# are not isolated entities  They interoperate in two ways:  By being part of a system written in more than one language  By accessing services and operating on a distributed environment  Requires support from run time:  .Net and the Common Language Runtime  .Net is many things, in particular binary object access  C# interoperates with .Net
  • 4. University of VirginiaCSharp (© John Knight 2005) 4 The Simple Stuff  Most of C# is pretty similar to languages you are used to:  Declarations  Expressions  Assignment and control statements  Other elements are quite similar:  Classes  Functions  Polymorphism
  • 5. University of VirginiaCSharp (© John Knight 2005) 5 Major Topics To Discuss  Identifier scope system—namespaces  Type system  Memory system and pointers  Execution time environment  Threads  Exceptions  Interfaces
  • 6. University of VirginiaCSharp (© John Knight 2005) 6 Namespaces Namespace CS415 Class A Class B Class C  Permits isolation of names  Can be nested  Access via fully qualified names Namespace CS340 Class A Class B Class C CS415.A… CS340.A…
  • 7. University of VirginiaCSharp (© John Knight 2005) 7 Type System  Type should be consistent:  Predefined and user-defined  All C# types derive from System.Object  Single rooted hierarchy  Provides four standard methods:  bool Equals  int GetHashCode  Type GetType  String ToString These don’t necessarily mean what you think Same object (ref) or same value (val) Retrieve object type (reflection) Retrieve object type (default)
  • 8. University of VirginiaCSharp (© John Knight 2005) 8 Types Of Types  Value types and reference types  Value types:  Program variables have a value  Space allocated on stack  Reference types:  Program variable is just a reference  Allocated space on stack  Reference is a “type-safe” pointer  Data space allocated on heap
  • 9. University of VirginiaCSharp (© John Knight 2005) 9 Value vs. Reference  Note the “special” status of primitive types System.Int32 myInt = 42; System.String myStr = “Hello World”; Circle c; c = new Circle(...); 42 address “Hello World” Stack Heap myStr myInt address Circle objectc Be careful with deallocation of the space
  • 10. University of VirginiaCSharp (© John Knight 2005) 10 Boxing And Unboxing  Conversion between value variable and reference variable System.Int32 myInt = 42; object o = myInt; int ymInt = (int)o; 42 o 42 Stack Heap Boxed myInt object o myInt
  • 11. University of VirginiaCSharp (© John Knight 2005) 11 The Role Of A Type System  What do we need from a type system?  Types across languages:  Consistency  Compatibility  Type safety:  Checking for meaningful statements  Add “speed” to “distance”?  C# vs Ada
  • 12. University of VirginiaCSharp (© John Knight 2005) 12 Memory Layout Stack Heap Garbage CollectorFunction Call & Return Pointers f() g() h() k() f calls g, g calls h, h calls k P*
  • 13. University of VirginiaCSharp (© John Knight 2005) 13 C# Memory Management  Static vs. dynamic  Dynamic storage—stack and heap  Stack (Dynamic):  Managed algorithmically by implementation of function calls  Heap (Dynamic)  Mostly managed by system  Provision for management by programmer
  • 14. University of VirginiaCSharp (© John Knight 2005) 14 C# Memory Management  Allocation using new  Deallocation by Garbage Collection  Garbage collection:  Tracks objects that are accessible  Frees storage associated with objects that are inaccessible  Garbage collector is a system provided service that runs periodically  Deals with fragmentation
  • 15. University of VirginiaCSharp (© John Knight 2005) 15 Garbage Collector Pros & Cons  Pros:  Programmer does not have to implement  Memory management done right  Cons:  No guarantee when it runs, hence no control  Takes processor resources  Does not delete storage if it is still reachable even if you don’t want it…  Memory leaks can (and do) still occur
  • 16. University of VirginiaCSharp (© John Knight 2005) 16 Some Specifics of C#  Object destruction via Object.Finalize:  Inherited from Object type  Override to destroy object as desired  Garbage collector available via GC class:  Runs via separate thread  Various methods available for access  E.g., GC.collect()  Pointers—yes, they are provided:  Syntax like C++, code marked unsafe  Objects managed by GC or user—pinned Object cannot be moved
  • 17. University of VirginiaCSharp (© John Knight 2005) 17 Traditional Compilation Source Program Compiler Object Program Linkage Editor Object Program Loader Binary Program Machine Instructions For Specific Target Object Code Libraries Relocatable Relocatable Not Relocatable Dynamic Linking Static Linking
  • 18. University of VirginiaCSharp (© John Knight 2005) 18 More Flexible Compilation Source Program Compiler Microsoft Intermediate Language (MSIL) Program TARGET Run-time Support System Machine Instructions For Multiple Targets TARGET Run-time Support System Interpreter Just-in-Time (JiT) Comp
  • 19. University of VirginiaCSharp (© John Knight 2005) 19 Concurrency  Threads vs. processes/tasks  C# supports threads Thread Thread Thread Thread Data Communication Who is running and when? What exactly are the problems here?
  • 20. University of VirginiaCSharp (© John Knight 2005) 20 C# Threads  System.Threading namespace  Facilities include:  Thread creation, destruction  Child thread management, e.g. join()  Thread scheduling, priority, timing  Synchronization:  Monitors  Semphores (mutex class)  Lock—serialization of statement block
  • 21. University of VirginiaCSharp (© John Knight 2005) 21 Exceptions  Why do we need exceptions?  How should they be made available in programming languages?  What benefits do they provide?  What problems could they cause for us?  Throw raises an exception  Catch defines a block that handles the exception  Etc.
  • 22. University of VirginiaCSharp (© John Knight 2005) 22 One Thing Is For Sure…  Exceptions are NOT for dealing with errors  They are a mechanism for changing the flow of control from sequential to a branch if certain conditions exist  They always indicate expected circumstances. Otherwise they could not possibly be generated