Another look at the C# (6.0) trickbox

Florian Rappl, MVP Visual C#

C# 6.0

Another look at the trickbox

C# 6 Trickbox

Florian Rappl

Writer and consultant

  • Microsoft C# MVP and CodeProject MVP
  • Active contributions to open-source projects
  • Company workshops, talks and IT consulting

Languages and technologies

  • C#, JavaScript and C/C++
  • Full web stack (client and server)
  • High Performance and Embedded Computing

Agenda

  1. C# 6: What's new?
  2. Classic Tricks
  3. Renewed Oldies
  4. Fresh Ones
  5. Roslyn and Meta-Programming
C# 6
Mads Torgersen
C# 6.0 adds about a dozen bite-sized new features to C#, all aimed at making your code cleaner and clearer.

Mads Torgersen
Program Manager for C#

using static

readonly properties

method expressions

index initializers

exception filtering

elvis operator

catchy await

C# 6 Classic Tricks

#1

switch to dictionary

#2

readonly vs. constants

#3

weak references

#4

partial methods

#5

params indexer

#6

debugger attributes

#7

copying memory fast

What's wrong here?

Two Bad Loops

#8

unions

#9

expose local state to friends

#10

abuse default

C# 6 Renewed Tricks

#11

create a stringbuilder pool

Performance gain

StringBuilder pooling

#12

init time branching

#13

configure await (probably)

#14

prevent boxing

#15

remove LINQ

#16

add LINQ

#17

consider aliasing

#18

operational enums

#19

variadic arguments

C# 6 Fresh Tricks

#20

optional invocation

#21

string interpolation

#22

use the tpl (wisely)

#23

don't use plinq (probably)

#24

await events

#25

use nameof

Roslyn Meta Programming

Roslyn in a single diagram

Roslyn Scheme

analyzers

code fixes

Conclusions

  • C# is more powerful than ever
  • Use nameof instead of literals
  • Think about IO vs CPU bound
  • Readability should be the primary concern
  • Measure performance to find bottlenecks
  • Embrace KISS, DRY and YAGNI
  • Roslyn will help us to standardize our code

Thanks for your attention

  • Feel free to contact me