C # 7, 8, and beyond: language features from design to release to IDE support. Kevin

Similar documents
Herding Nulls. and other C# stories from the future. Mads Torgersen, C# lead designer Microsoft

Introduce C# as Object Oriented programming language. Explain, tokens,

Upcoming Features in C# Mads Torgersen, MSFT

Java and C# in Depth

inside: THE MAGAZINE OF USENIX & SAGE August 2003 volume 28 number 4 PROGRAMMING McCluskey: Working with C# Classes

Whom Is This Book For?... xxiv How Is This Book Organized?... xxiv Additional Resources... xxvi

C# Programming in the.net Framework

DAD Lab. 1 Introduc7on to C#

Learn C# Errata. 3-9 The Nullable Types The Assignment Operators

Prerequisites: The student should have programming experience in a high-level language. ITCourseware, LLC Page 1. Object-Oriented Programming in C#

Industrial Programming

What is an Object. Industrial Programming. What is a Class (cont'd) What is a Class. Lecture 4: C# Objects & Classes

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including:

What property of a C# array indicates its allocated size? What keyword in the base class allows a method to be polymorphic?

Course Hours

Equality in.net. Gregory Adam 07/12/2008. This article describes how equality works in.net

Semantic & Immutable Types

Microsoft Visual C# Step by Step. John Sharp

The C# Programming Language. Overview

How to be a C# ninja in 10 easy steps. Benjamin Day

Object-Oriented Programming in C# (VS 2015)

CORE JAVA TRAINING COURSE CONTENT

C#: framework overview and in-the-small features

Object-Oriented Programming in C# (VS 2012)

Chapter 1 Getting Started

1 C# 6.0: Practical Guide 6.0. Practical Guide. By: Mukesh Kumar.

Rx is a library for composing asynchronous and event-based programs using observable collections.

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

Tomas Petricek. F# Language Overview

Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.)

With great C++ comes great responsibility

MCSA Universal Windows Platform. A Success Guide to Prepare- Programming in C# edusum.com

Introduction to C# Applications

Concepts of programming languages

public class Test { public static int i = 0;

CSE 431S Type Checking. Washington University Spring 2013

CSC 210, Exam Two Section February 1999

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

Objectives. Introduce static keyword examine syntax describe common uses

Mobile SDK for Xamarin - SSC 1.1 Rev: September 13, Mobile SDK for Xamarin - SSC 1.1

An introduction to Java II

Ryerson University Department of Electrical & Computer Engineering COE618 Midterm Examination February 26, 2013

CSC 1351: Final. The code compiles, but when it runs it throws a ArrayIndexOutOfBoundsException

Inheritance (Part 5) Odds and ends

Future of Java. Post-JDK 9 Candidate Features. Jan Lahoda Java compiler developer Java Product Group, Oracle September, 2017

Scala : an LLVM-targeted Scala compiler

One language to rule them all: TypeScript. Gil Fink CEO and Senior Consultant, sparxys

C# s A Doddle. Steve Love. ACCU April 2013

In this lab we will practice creating, throwing and handling exceptions.

Goals for Today. CSE1030 Introduction to Computer Science II. CSE1030 Lecture #4. Review: Methods / Code

Bugs in software. Using Static Analysis to Find Bugs. David Hovemeyer

Effective C# Presentation By: Brian Braatz. Derived from the book Effective C# 2 nd Edition

PES INSTITUTE OF TECHNOLOGY

Let s get started! You first need to download Visual Studio to edit, compile and run C# programs. Download the community version, its free.

Java Persistence API (JPA) Entities

University of Palestine. Mid Exam Total Grade: 100

CS 231 Data Structures and Algorithms, Fall 2016

Announcements. Java Review. More Announcements. Today. Assembly Language. Machine Language

CS 149. Professor: Alvin Chao

Previous C# Releases. C# 3.0 Language Features. C# 3.0 Features. C# 3.0 Orcas. Local Variables. Language Integrated Query 3/23/2007

Remedial classes. G51PRG: Introduction to Programming Second semester Lecture 2. Plan of the lecture. Classes and Objects. Example: Point class

CMSC 132: Object-Oriented Programming II. Inheritance

Grand Central Dispatch. Sri Teja Basava CSCI 5528: Foundations of Software Engineering Spring 10

COE318 Lecture Notes Week 9 (Week of Oct 29, 2012)

import org.simpleframework.xml.default; import org.simpleframework.xml.element; import org.simpleframework.xml.root;

Introduction to Haskell

C# COMO VOCÊ (TALVEZ) NUNCA VIU

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Haskell Programming

Goals for Today. CSE1030 Introduction to Computer Science II. CSE1030 Lecture #9. Review is-a versus has-a. Lecture #9 Inheritance I

Recommendation: Play the game and attempt to answer the questions yourself without looking at the answers. You ll learn much less if you just look at

Five Reasons to Move from C# to F#

Program Representations

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

Questions. Exams: no. Get by without own Mac? Why ios? ios vs Android restrictions. Selling in App store how hard to publish? Future of Objective-C?

.Net Technologies. Components of.net Framework

Intermediate Code Generation

and why you should care but probably don t

Recursion CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2011

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

Runtime code generation techniques in real life scenarios

python. a presentation to the Rice University CS Club November 30, 2006 Daniel Sandler

1. Find the output of following java program. class MainClass { public static void main (String arg[])

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Recursion. Overview. Mathematical induction. Hello recursion. Recursion. Example applications. Goal: Compute factorial N! = 1 * 2 * 3...

Repository Pattern and Unit of Work with Entity Framework

Pointers, Dynamic Data, and Reference Types

Applied object oriented programming. 4 th lecture

Administrivia. Java Review. Objects and Variables. Demo. Example. Example: Assignments

Course Syllabus C # Course Title. Who should attend? Course Description

Applied Unified Ownership. Capabilities for Sharing Across Threads

Tutorial 4. Values and References. Add One A. Add One B. Add One C

Status Report. JSR-305: Annotations for Software Defect Detection. William Pugh Professor

Functions! Objectives! 1E3! Topic 9! programming! n This topic should allow students to! n Read chapter 6 of the textbook now.!

Concurrency & Parallelism. Threads, Concurrency, and Parallelism. Multicore Processors 11/7/17

This tutorial has been prepared for the beginners to help them understand basics of c# Programming.

Selected Questions from by Nageshwara Rao

These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without

Accessing loosely structured data from F# and C# Tomas Petricek PhD Student Microsoft C# MVP

CSC 1052 Algorithms & Data Structures II: Linked Lists Revisited

Transcription:

C # 7, 8, and beyond: language features from design to release to IDE support Kevin Pilch kevinpi@microsoft.com @Pilchie

Stack Overflow - most popular technologies http://stackoverflow.com/insights/survey/2017#most-popular-technologies

Stack Overflow - most loved technologies http://stackoverflow.com/insights/survey/2017#most-loved-dreaded-and-wanted

Changing the tune - Why you can use C# Run on Windows Black box compilers Edit in Visual Studio Proprietary Run everywhere Open compiler APIs Use your favorite editor Open source

C# everywhere - Xamarin

C# everywhere - Unity

C# everywhere -.NET Core

Roslyn the C# language engine There should need to be only one code base in the world for understanding C#

OmniSharp edit C# everywhere

C# Evolution A balancing act Aggressively improve Attractive to new users Embrace new paradigms Stay simple Improve existing development Stay true to the spirit of C#

C# - evolution C# 7 C# 1 C# 2 Generics C# 3 Queries, Lambdas C# 4 Dynamic, Concurrency C# 5 Async C# 6 Eliminate ceremony Work with data Hello World

C# 6 - recap Expression bodied members String Interpolation Conditional access operator nameof Using static Exception Filters Interactive window

Demo: C# 7.0

C# 7.0 what s new static void Main(string[] args) { object[] numbers = { 0b1, 0b10, new object[] { 0b100, 0b1000 }, // binary literals 0b1_0000, 0b10_0000 }; // digit separators } var (sum, count) = Tally(numbers); WriteLine($"Sum: {sum}, Count: {count}"); // deconstruction static (int sum, int count) Tally(object[] values) { var r = (s: 0, c: 0); void Add(int s, int c) { r.s += s, r.c += c; } // tuple types // tuple literals // local functions } return r;

C# 7.0 what s new static (int sum, int count) Tally(object[] values) { var r = (s: 0, c: 0); void Add(int s, int c) { r.s += s, r.c += c; } foreach (var v in values) { switch (v) { case int i: Add(i, 1); break; case object[] a when a.length > 0: var t = Tally(a); Add(t.sum, t.count); break; } } return r; } // tuple types // tuple literals // local functions // switch on any value // type patterns // case conditions

Binary literals Digit separators Tuples Patterns Local functions Tasklike async methods Out var ref locals and returns Throw expressions More expression bodied members C# 7.0 what s new

C# 7.1 introducing point releases default expressions Async main Infer tuple names Reference assemblies

C# 7.2, 8.0, long term thinking ref readonly blittable Interior pointer (needed for Span<T>) Nullable Reference Types Default Interface methods

Nullable and non-nullable reference types string? n; // Nullable reference type string s; // Non-nullable reference type n = null; // Sure; it's nullable s = null; // Warning! Shouldn t be null! s = n; // Warning! Really! WriteLine(s.Length); // Sure; it s not null WriteLine(n.Length); // Warning! Could be null! if (n!= null) { WriteLine(n.Length); } // Sure; you checked WriteLine(n!.Length); // Ok, if you insist!

Default implementations public interface IEnumerator { object Current { get; } bool MoveNext(); void Reset() => throw new InvalidOperationException("Reset not supported"); } public interface IEnumerator<out T> : IDisposable, IEnumerator { new T Current { get; } object IEnumerator.Current => Current; }

C# 8.0, long term thinking Extension Everything Async Streams and Disposables More patterns: recursive, tuples, expressions, etc Records Discriminated Unions Creating Immutable objects

Extension everything extension Enrollee extends Person { // static field static Dictionary<Person, Professor> enrollees = new(); // instance method public void Enroll(Professor supervisor) { enrollees[this] = supervisor; } // instance property public Professor Supervisor => enrollees.trygetvalue(this, out var supervisor)? supervisor : null; // static property public static ICollection<Person> Students => enrollees.keys; } // instance constructor public Person(string name, Professor supervisor) : this(name) { this.enroll(supervisor); }

Async streams and disposables IAsyncEnumerable<Person> people = database.getpeopleasync(); foreach await (var person in people) { // use person } using await (IAsyncDisposable resource = await store.getrecordasync( )) { // use resource }

Recursive patterns if (o is Point(_, var y)) { WriteLine($"Y: {y}"); } if (o is Point { Y: var y }) { WriteLine($"Y: {y}"); }

Pattern matching expressions var s = match (o) { }; int i case Point(int x, int y) string s when s.length > 0 => s, null _ => $"Number {i}", => $"({x},{y})", => "<null>", => "<other>"

Tuples in patterns state = match (state, request) { } (Closed, Open) (Closed, Lock) => Opened, => Locked, (Opened, Close) => Closed, (Locked, Unlock) => Closed, _ => throw new InvalidOperationException( )

Records and discriminated unions record Person(string First, string Last); class Person : IEquatable<Person> { public string First { get; } public string Last { get; } public Person(string First, string Last) { this.first = First; this.last = Last; } public void Deconstruct(out string first, out string last){ first = First; last = Last; } public bool Equals(Person other) => other!= null && First == other.first && Last == other.last; } public override bool Equals(object obj) => obj is Person other? Equals(other) : false; public override int GetHashCode() => GreatHashFunction(First, Last);

Creating immutable objects var p1 = new Point { X = 3, Y = 7 }; var p2 = p1 with { X = -p1.x };

Questions and resources? Language Implementation Reference Contact Content Me https://github.com/dotnet/csharplang https://github.com/dotnet/roslyn http://source.roslyn.io https://twitter.com/roslyn https://github.com/pilchie/qconsp/ kevinpi@microsoft.com @Pilchie Twitter/GitHub