University of Virginia CSharp (© John Knight 2005) 1 What’s New In C#

Slides:



Advertisements
Similar presentations
Names and Bindings.
Advertisements

Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
.NET Framework Overview Pingping Ma Nov 16 th, 2006.
The Type System1. 2.NET Type System The type system is the part of the CLR that defines all the types that programmers can use, and allows developers.
3/17/2008Prof. Hilfinger CS 164 Lecture 231 Run-time organization Lecture 23.
1 Names, Scopes and Bindings. 2 Names Kinds of names Kinds of names Variables, functions, classes, types, labels, blocks, operators, tasks, etc. Variables,
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Run time vs. Compile time
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
C#/.NET Jacob Lewallen. C# vs.NET.NET is a platform. Many languages compile to.NET: –VB.NET –Python.NET –Managed C++ –C#
Reference Types. 2 Objectives Introduce reference types –class –array Discuss details of use –declaration –allocation –assignment –null –parameter –aggregation.
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
Abstract Data Types and Encapsulation Concepts
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
From C++ to C#. Web programming The course is on web programming using ASP.Net and C# The course is on web programming using ASP.Net and C# ASP.Net is.
OOP Languages: Java vs C++
11 Values and References Chapter Objectives You will be able to: Describe and compare value types and reference types. Write programs that use variables.
Programming Languages and Paradigms Object-Oriented Programming.
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Names Variables Type Checking Strong Typing Type Compatibility 1.
SPL/2010 StackVsHeap. SPL/2010 Objectives ● Memory management ● central shared resource in multiprocessing RTE ● memory models that are used in Java and.
Adapted from Prof. Necula UCB CS 1641 Overview of COOL ICOM 4029 Lecture 2 ICOM 4029 Fall 2008.
Computing with C# and the.NET Framework Chapter 1 An Introduction to Computing with C# ©2003, 2011 Art Gittleman.
Programming Language C++ Xulong Peng CSC415 Programming Languages.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
COMPILERS Symbol Tables hussein suleman uct csc3003s 2007.
Basic Semantics Associating meaning with language entities.
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
1 Records Record aggregate of data elements –Possibly heterogeneous –Elements/slots are identified by names –Elements in same fixed order in all records.
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.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 9.
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
COMP3190: Principle of Programming Languages
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
PRIOR TO WEB SERVICES THE OTHER TECHNOLOGIES ARE:.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
Object Oriented Software Development 4. C# data types, objects and references.
CS212: Object Oriented Analysis and Design Lecture 19: Exception Handling.
C# and.NET. .NET Architecture  Compiling and running code that targets.NET  Advantages of Microsoft Intermediate Language (MSIL)  Value and Reference.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
CIS 200 Test 01 Review. Built-In Types Properties  Exposed “Variables” or accessible values of an object  Can have access controlled via scope modifiers.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
Design issues for Object-Oriented Languages
Object Lifetime and Pointers
Java Yingcai Xiao.
CIS 200 Test 01 Review.
Andy Wang Object Oriented Programming in C++ COP 3330
Java Programming Language
C# and the .NET Framework
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Binding Times Binding is an association between two things Examples:
Programming Languages
ICOM 4029 Fall 2003 Lecture 2 (Adapted from Prof. Necula UCB CS 164)
SPL – PS1 Introduction to C++.
Presentation transcript:

University of Virginia CSharp (© John Knight 2005) 1 What’s New In C#

University of Virginia CSharp (© John Knight 2005) 2 C# Genealogy FortranAlgol 68CC++C# Cobol Eiffel JavaAda 95PL/I Pascal Elementary Procedural Advanced Procedural Special Procedural Object Oriented Advanced Object Oriented Ada 83

University of Virginia CSharp (© 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 Virginia CSharp (© 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 Virginia CSharp (© 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 Virginia CSharp (© 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 Virginia CSharp (© 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 Virginia CSharp (© 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 Virginia CSharp (© 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 addressCircle object c Be careful with deallocation of the space

University of Virginia CSharp (© 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 Stack Heap Boxed myInt object o myInt

University of Virginia CSharp (© 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 Virginia CSharp (© 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 Virginia CSharp (© 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 Virginia CSharp (© 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 Virginia CSharp (© 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 Virginia CSharp (© 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 Virginia CSharp (© 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 Not Relocatable Dynamic Linking Static Linking

University of Virginia CSharp (© 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 Virginia CSharp (© John Knight 2005) 19 Concurrency  Threads vs. processes/tasks  C# supports threads Thread Data Communication Who is running and when? What exactly are the problems here?

University of Virginia CSharp (© 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 Virginia CSharp (© 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 Virginia CSharp (© 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