.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.

Slides:



Advertisements
Similar presentations
Arrays.
Advertisements

CERTIFICATION OBJECTIVES Use Class Members Develop Wrapper Code & Autoboxing Code Determine the Effects of Passing Variables into Methods Recognize when.
C#: Data Types Based on slides by Joe Hummel. 2 UCN Technology: Computer Science Content: “.NET is designed around the CTS, or Common Type System.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
ISBN Chapter 6 Data Types: Structured types.
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++
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#
Review of C++ Programming Part II Sheng-Fang Huang.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Programming in C# Language Overview
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Introduction to C# C# is - elegant, type-safe, object oriented language enabling to build applications that run on the.NET framework - types of applications.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
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.
Understanding Data Types and Collections Lesson 2.
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Object Oriented Software Development 4. C# data types, objects and references.
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
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 –
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
Value Types. 2 Objectives Discuss concept of value types –efficiency –memory management –value semantics –boxing –unboxing –simple types Introduce struct.
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
Understanding Data Types and Collections Lesson 2.
C++ LANGUAGE MULTIPLE CHOICE QUESTION SET-3
Constructors and Destructors
Minimising memory churn
Data Types In Text: Chapter 6.
Creating and Using Objects, Exceptions, Strings
Sixth Lecture ArrayList Abstract Class and Interface
Chapter 6 – Data Types CSCE 343.
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Type Checking, and Scopes
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
CIS 200 Test 01 Review.
Andy Wang Object Oriented Programming in C++ COP 3330
Java Primer 1: Types, Classes and Operators
Module 5: Common Type System
Review: Two Programming Paradigms
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Computing with C# and the .NET Framework
C# Programming Arrays in C# Declaring Arrays of Different Types Initializing Array Accessing Array Elements Creating User Interfaces Using Windows Standards.
Functional Programming with Java
Advanced Programming Behnam Hatami Fall 2017.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes
.NET and .NET Core 9. Towards Higher Order Pan Wuming 2017.
Object Oriented Programming (OOP) LAB # 8
Data Types and Expressions
7 Arrays.
1.2 Key Concepts and Walkthroughs
Pointers C#, pointers can only be declared to hold the memory addresses of value types int i = 5; int *p; p = &i; *p = 10; // changes the value of i to.
Arrays and Collections
Object Oriented Programming in java
Constructors and Destructors
7 Arrays.
Introduction to Data Structure
CIS 199 Final Review.
Java Programming Language
Java Basics Data Types in Java.
Quiz Points 1 Rules Raise your hand if you know the question
5. 3 Coding with Denotations
Review of Java Fundamentals
Interfaces, Enumerations, Boxing, and Unboxing
Presentation transcript:

.NET and .NET Core 5.2 Type Operations Pan Wuming 2016

Topics Elementary Types Casting and Type Conversions Boxing and Unboxing Implicit Types Anonymous Types Nullable types Dynamic as and is Operators Three new languages: C#, IL and F# Evolving from OO Paradigm Everything is object Members for Abstraction Accessibility for Encapsulation Inheritance and Polymorphism Solving name confliction and multi-inheritance Towards higher order: Expressiveness Delegate Lambda Expression Generic Attribute LINQ Compiler API Effective coding References: Types (C# Programming Guide)(MSDN)

Types, Variables, and Values C# is a strongly-typed language. The information stored in a type can include the following The storage space that a variable of the type requires. The maximum and minimum values that it can represent. The members (methods, fields, events, and so on) that it contains. The base type it inherits from. The location where the memory for variables will be allocated at run time. The kinds of operations that are permitted.

Built-in Types Integers: byte, int… Floating point values: float, double… Boolean expressions: bool Text characters: char Decimal values: decimal String: string Object Array

Strings A string is an object of type String whose value is text. Internally, the text is stored as a sequential read-only collection of Char objects. A C# string can contain any number of embedded null characters ('\0'). The Length property of a string String objects are immutable

Creating, Manipulating, Format, and Comparing Strings

Using StringBuilder for Fast String Creation StringBuilder objects are not immutable.

Related Topics about String (MSND)

Interning of Strings A table called the intern pool that contains a single reference to each unique literal string An instance of a literal string with a particular value only exists once in the system The Intern method The IsInterned method

Arrays: to store multiple variables of the same type An array can be Single-Dimensional, Multidimensional or Jagged. The number of dimensions and the length of each dimension can't be changed The default values of array elements. A jagged array is an array of arrays. Arrays are zero indexed: an array with n elements is indexed from 0 to n-1. Array elements can be of any type, including an array type. Array types are reference types derived from the abstract base type Array. To use foreach iteration on all arrays in C#.

Dynamically Increase An Array’s Size Using The List< T> class or the ArrayList class Frequently used methods and properties in List< T> Add and AddRange Insert Count (is the counterpart of Length property in Array) ElementAt Remove and RemoveRange Sort

Casting and Type Conversions Implicit conversions Explicit conversions (casts) Data loss might occur Convert from a base type to a derived type User-defined conversions Conversions with helper classes, such as the System. Convert class

Conversion Operators Conversions are named for the type to which they convert. Either the type of the argument or the type of the result of the conversion must be the containing type. Conversions declared as implicit occur automatically when it is required. Conversions declared as explicit require a cast to be called. All conversions must be declared as static.

Checked The checked keyword is used to explicitly enable overflow checking for integral-type arithmetic operations and conversions. When overflow occurs an overflow exception is raise. The unchecked keyword is used to suppress overflow-checking

Common Type System (CTS): Unified Type Hierarchy

Value Types Value types derive from System.ValueType There are two categories of value types: struct and enum Boxing and Unboxing

Boxing and Unboxing Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type. Boxing a value type allocates an object instance on the heap and copies the value into the new object Unboxing extracts the value type from the object. Boxing is implicit; unboxing is explicit.

Unboxing Checking the object instance to make sure that it is a boxed value of the given value type. Copying the value from the instance into the value-type variable.

Implicit Types To Implicitly type a local variable by var The compiler determines and assigns the most appropriate type to the variable

Anonymous Types To encapsulate a set of read-only properties into a single object without a type definition. Using the new operator together with an object initializer Anonymous types are class types that derive directly from object. Array of anonymously typed elements

if(x.HasValue) j = x.Value; Nullable types Being useful when passing data to and from certain databases The syntax T? is shorthand for Nullable<T>, whereT is a value type. Assign a value to a nullable type Nullable<T>.GetValueOrDefault Use the HasValue and Value read-only properties if(x.HasValue) j = x.Value;

Using Type dynamic An object of type dynamic bypasses static type checking At compile time, an element that is typed as dynamic is assumed to support any operation. The dynamic language runtime (DLR) is a new API in .NET Framework 4. the dynamic type in C# the implementation of dynamic programming languages such as IronPython

Improve the experience of interoperating with COM APIs

Safely Cast by Using as and is Operators

See You Next Class Learn the whole when you are learning, then you are really learning! Xun Zi