What s new in c
Download
1 / 22

what - PowerPoint PPT Presentation


  • 200 Views
  • Updated On :

What’s New In C#. C# Genealogy. Object Oriented. Advanced Object Oriented. Elementary Procedural. Advanced Procedural. Special Procedural. Eiffel. Fortran. Algol 68. C. C++. C#. Cobol. PL/I. Ada 95. Java. Pascal. Ada 83. C# And .Net. Languages like C# are not isolated entities

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'what' - emily


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
What s new in c l.jpg

What’s New In C#

CSharp (© John Knight 2005)


C genealogy l.jpg
C# Genealogy

ObjectOriented

AdvancedObjectOriented

ElementaryProcedural

AdvancedProcedural

SpecialProcedural

Eiffel

Fortran

Algol 68

C

C++

C#

Cobol

PL/I

Ada 95

Java

Pascal

Ada 83

CSharp (© John Knight 2005)


C and net l.jpg
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

CSharp (© John Knight 2005)


The simple stuff l.jpg
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

CSharp (© John Knight 2005)


Major topics to discuss l.jpg
Major Topics To Discuss

  • Identifier scope system—namespaces

  • Type system

  • Memory system and pointers

  • Execution time environment

  • Threads

  • Exceptions

  • Interfaces

CSharp (© John Knight 2005)


Namespaces l.jpg
Namespaces

  • Permits isolation of names

  • Can be nested

  • Access via fully qualified names

Namespace CS415

Class A

Class B

Class C

Namespace CS340

Class A

Class B

Class C

CS415.A…

CS340.A…

CSharp (© John Knight 2005)


Type system l.jpg
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

Same object (ref) or same value (val)

Retrieve object type (reflection)

Retrieve object type (default)

These don’t necessarily mean what you think

CSharp (© John Knight 2005)


Types of types l.jpg
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

CSharp (© John Knight 2005)


Value vs reference l.jpg
Value vs. Reference

  • Note the “special” status of primitive types

    System.Int32 myInt = 42;System.String myStr = “Hello World”;Circle c;c = new Circle(...);

Heap

Stack

Be careful with deallocation of the space

42

myInt

address

“Hello World”

myStr

address

Circle object

c

CSharp (© John Knight 2005)


Boxing and unboxing l.jpg
Boxing And Unboxing

  • Conversion between value variable and reference variable

    System.Int32 myInt = 42;object o = myInt;int ymInt = (int)o;

Heap

Stack

42

myInt

Boxed

myInt

object o

o

42

CSharp (© John Knight 2005)


The role of a type system l.jpg
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

CSharp (© John Knight 2005)


Memory layout l.jpg
Memory Layout

Heap

Stack

f calls g, g calls h, h calls k

P*

Pointers

g()

h()

k()

f()

Function Call & Return

Garbage Collector

CSharp (© John Knight 2005)


C memory management l.jpg
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

CSharp (© John Knight 2005)


C memory management14 l.jpg
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

CSharp (© John Knight 2005)


Garbage collector pros cons l.jpg
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

CSharp (© John Knight 2005)


Some specifics of c l.jpg
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

CSharp (© John Knight 2005)


Traditional compilation l.jpg
Traditional Compilation

Machine Instructions For Specific Target

Source

Program

Compiler

Object Code

Libraries

Relocatable

Static Linking

Object

Program

Linkage

Editor

Dynamic Linking

Not Relocatable

Relocatable

Object

Program

Loader

Binary

Program

CSharp (© John Knight 2005)


More flexible compilation l.jpg
More Flexible Compilation

Source

Program

Compiler

MicrosoftIntermediateLanguage (MSIL)

Program

Machine InstructionsFor Multiple Targets

TARGET

TARGET

Interpreter

Just-in-Time (JiT) Comp

Run-time Support System

Run-time Support System

CSharp (© John Knight 2005)


Concurrency l.jpg
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 2005)


C threads l.jpg
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

CSharp (© John Knight 2005)


Exceptions l.jpg
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?

  • Throwraises an exception

  • Catch defines a block that handles the exception

  • Etc.

CSharp (© John Knight 2005)


One thing is for sure l.jpg
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

CSharp (© John Knight 2005)


ad