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.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

Elementary Data Types Prof. Alamdeep Singh. Scalar Data Types Scalar data types represent a single object, i.e. only one value can be derived. In general,
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
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++
C#: Project Cool Arthur Ketchel II Keith Francisco Chris McInnis.
C#/.NET Jacob Lewallen. C# vs.NET.NET is a platform. Many languages compile to.NET: –VB.NET –Python.NET –Managed C++ –C#
Elementary Data Types Scalar Data Types Numerical Data Types Other
Introducing the Common Language Runtime for.NET. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution.
1 Type Type system for a programming language = –set of types AND – rules that specify how a typed program is allowed to behave Why? –to generate better.
University of Virginia CSharp (© John Knight 2005) 1 What’s New In C#
Introducing the Common Language Runtime. The Common Language Runtime The Common Language Runtime (CLR) The Common Language Runtime (CLR) –Execution engine.
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#
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.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
OOP Languages: Java vs C++
MT311 Java Application Programming and Programming Languages Li Tak Sing ( 李德成 )
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Programming Languages and Paradigms Object-Oriented Programming.
.NET Framework Introduction: Metadata
1 8/29/05CS360 Windows Programming Professor Shereen Khoja.
Module 1: Introduction to C# Module 2: Variables and Data Types
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
Names Variables Type Checking Strong Typing Type Compatibility 1.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
Object Oriented Programming: Java Edition By: Samuel Robinson.
.NET Framework Danish Sami UG Lead.NetFoundry
Mason Vail.  A data type definition – “blueprint for objects”  Includes properties and/or methods ◦ “instance” data / methods – specific to one object.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
Introduction to C# C# is - elegant, type-safe, object oriented language enabling to build applications that run on the.NET framework - types of applications.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Introduction to Object Oriented Programming CMSC 331.
.NET common type system. Role of type system provides a logically consistent and unchanging foundation ensures that programs can be checked for correctness.
Hoang Anh Viet Hà Nội University of Technology Chapter 1. Introduction to C# Programming.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Copyright © Curt Hill Structured Data What this course is about.
Visual C# 2012 for Programmers © by Pearson Education, Inc. All Rights Reserved.
Types(1). Lecture 52 Type(1)  A type is a collection of values and operations on those values. Integer type  values..., -2, -1, 0, 1, 2,...  operations.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
Object-Oriented Programming Chapter Chapter
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
ISBN Object-Oriented Programming Chapter Chapter
Introduction to Object-Oriented Programming Lesson 2.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
Object Oriented Software Development 4. C# data types, objects and references.
Duke CPS From C++ to Java l Java history: Oak, toaster-ovens, internet language, panacea l What it is ä O-O language, not a hybrid (cf. C++)
Variables reference, coding, visibility. Rules for making names  permitted character set  maximum length, significant length  case sensitivity  special.
1 CS Programming Languages Class 22 November 14, 2000.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
CS 330 Programming Languages 10 / 23 / 2007 Instructor: Michael Eckmann.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
July 22, 2001Introduction to.NET1 Introduction to.NET Framework Gholamali Semsarzadeh July 2001.
The Execution System1. 2 Introduction Managed code and managed data qualify code or data that executes in cooperation with the execution engine The execution.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
ISBN Chapter 12 Support for Object-Oriented Programming.
METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Module 5: Common Type System
Object-Oriented Programming & Design Lecture 14 Martin van Bommel
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
CS360 Windows Programming
Java Programming Language
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

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 to define new types (interfaces, methods etc.). –A type is a definition, from which value can be instantiated. –Types have members (fields or methods). Supports many of the types and operations found in modern programming languages

The Type System3 Evolution of Type Systems No type system – treats memory as sequence of bytes Built-in abstractions of common types – characters, integers etc. User-defined types Dynamic type checking

The Type System4 Design Challenge Type systems provided by many programming languages are incompatible. E.g. C, C++, SmallTalk, Java Developing a single type system for multiple languages poses a difficult design challenge..NET’s approach to CLR design: accommodates most of the common types and operations supported in modern object-oriented programming languages

The Type System5 CLR – Programming Language Interaction C++, C#, VB.NET Execution System Intermediate Language (IL) Code and Metadata Source File Language- Specific.NET Compiler Executable File Runtime Types/Metadata can be imported by can be referenced by

The Type System6 CLR Type System CLR Type System Value Types Reference Types Built-in Value Types Object Types Interface Types Pointer Types User-Defined Value Types User-Defined Reference Types

The Type System7

8 CLR Type System Value Type –Consists of a sequence of bits in memory –Simple or primitive types e.g. a 32-bit integer (build-in) –User-defined e.g. structures –Compared by equality (data value) –Inherits from System.ValueType or System.Enum –cannot be inherited by other types (i.e. sealed) –Allocated on stack Reference Type –Combines the address of a value and the value’s sequence of bits –Can be compared by identity (same object?) or equality (same data?) –e.g. classes, interface, array, string –Can be sealed or not –Allocated on heap, only with a reference on the stack

The Type System9 Fig 3-2

The Type System10 CLR Built-in Value Types CIL NameBase Framework Name (Framework Class Library) DescriptionCLS Support boolSystem.BooleanBoolean, true or falseY charSystem.CharUnicode characterY int8System.SByteSigned 8-bit integerN int16System.Int16Signed 16-bit integerY int32System.Int32Signed 32-bit integerY int64System.Int64Signed 64-bit integerY unsigned int8System.ByteUnsigned 8-bit integerY unsigned int16System.UInt16Unsigned 16-bit integerN unsigned int32System.UInt32Unsigned 32-bit integerN unsigned int64System.UInt64Unsigned 64-bit integerN float32System.SingleIEEE 32-bit floating-point numberY float64System.DoubleIEEE 64-bit floating-point numberY native intSystem.IntPtrSigned native integer, equivalent to the machine word size (32 bits on a 32-bit machine, 64 bits on a 64-bit machine) Y native unsigned int System.UIntPtrUnsigned native integerN

The Type System11 User-Defined Value Types Enumerations –A way to name a group of values of some integer type –Used to define types whose values have meaningful names rather than just numbers Structures, can contain –A collection of elements of various types –Methods (both static and instance) –Fields (both static and instance) –Properties (both static and instance) Logical field of a type, system generated accessors (get_ & set_) –Events (both static and instance) Used to expose asynchronous changes in an observed event

The Type System12 Enumeration Module Module1 Enum CardSuit clubs = 0 diamonds = 1 hearts = 2 spades = 3 End Enum Sub Main() Dim cs As CardSuit = CardSuit.hearts System.Console.Out.WriteLine("The value cs is {0}", cs) End Sub End Module

The Type System13 Structure Module Module1 Structure PixelCoord Public x As Single Public y As Single End Structure Sub Main() Dim p As PixelCoord p.x = 200 p.y = 100 System.Console.Out.WriteLine ("The value p.x is {0}", p.x) System.Console.Out.WriteLine("The value p.y is {0}", p.y) End Sub End Module

The Type System14 Reference Types Combines the address of a value and the value’s sequence of bits Accessed through a strongly typed reference Allocated on the garbage collected heap Three main categories –Object Types –Interface Types –Pointer Types

The Type System15 Object Types Object –All object types inherit, either directly or indirectly, from the CLR type System.Object class –Key methods: Equals(), Finalize(), GetHashCode(), GetType(), MemberwiseClone(), ReferenceEquals(), ToString() String –Sealed, immutable, allows greater optimization –Key methods: Compare(), Concatenate(), Conversion() etc. –Key properties: Length

The Type System16 Interface Types A partial specification of a type, binds implementers to provide implementations of the members contained in the interface. An interface type may define –Methods (static or instance) –Fields (static) –Properties (static or instance) –Events (static or instance) All instance methods in an interface are public, abstract, and virtual

The Type System17 Pointer Types Provide a means of specifying the location of either code or a value Three pointer types –Unmanaged function pointers refer to code –Unmanaged pointers refer to values –Managed Pointers are known to the garbage collector and are updated if they refer to an item that is moved on the garbage collected heap

The Type System18 Some Types Issues Assignment Compatibility (Listing 2.10) –A reference type T, can refer to an object With an exact type of T, or That is a subtype of T, or That supports the interface T Nested Types: types inside of other types (inner class) Visibility: refers to whether a type is available outside its assembly (export or not) Accessibility: members of a type can have different accessibility levels –public: available to all types –assembly: available to all types within this assembly –family: available in the type’s definition and all its subtypes –Private: available only in the type’s definition