10 dingen die je niet wist over C#. ALM ALM Ranger Microsoft Auteur Getrouwd Lezen C#

Slides:



Advertisements
Similar presentations
Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
Advertisements

Introduction to Web Application
JVM Internals Douglas Q. Hawkins. JVM Internals Bytecode Garbage Collection Optimizations Compile Time Run Time.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
1 Visual C# "Whidbey": Language Enhancements Anders Hejlsberg Distinguished Engineer Microsoft Corporation Anders Hejlsberg Distinguished.
5 Misconceptions about.NET Memory Management Wednesday June 1 st 2011 Clive Tong and Andrew Hunter.
TechReady 16 4/1/2017 Async Clinic
pa 1 Porting BETA to ROTOR ROTOR Projects Presentation Day, June by Peter Andersen.
Execute Blocks of Code Multiple Times Svetlin Nakov Telerik Corporation
public int Abs(int x) { if (x < 0) return -x; else return x; } public int Abs(int x) { if (x < 0) return -x;
The Dafny program verifier
static void Main() { int i = 0; if (i == 0) { int a = 5; int b = 15; if (a == 5) { int c = 3; int d = 99; }
... a programming language. ...a functional programming language.
Execute Blocks of Code Multiple Times Telerik Software Academy C# Fundamentals – Part 1.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 6 th Lecture Pavel Ježek
ASP.NET Best Practices Dawit Wubshet Park University.
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
Extension Methods, Anonymous Types LINQ Query Keywords, Lambda Expressions Svetlin Nakov Telerik Corporation
Web Applications HTML5 Games Windows 8 HTML Apps Basic Web Pages JavaScript Execution Speed DOM Interactions Accelerated Graphics Page Load Time.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Static Members, Structures, Enumerations, Generic Classes, Namespaces Learning & Development Team Telerik Software Academy.
Windows form application using System.Windows.Forms; using System.Drawing; class MyForm:Form{ public static void Main(){ Application.Run(new.
How to be a C# ninja in 10 easy steps. Benjamin Day.
Equality Programming in C# Equality CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
Arrays and Lists.  Properties ◦ Contents are stored in contiguous memory locations ◦ Elements of the array are of the same type  (Perl allows for.
2. Developing in.NET and C#. 2 Microsoft Objectives “Microsoft.NET development is based on an underlying framework of tools and classes. These tools and.
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Managed Code Generics Language Integrated Query Dynamic + Language Parity C# VB 11.0 Windows Runtime + Asynchrony C# VB 7.0 C# VB.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
11 Values and References Chapter Objectives You will be able to: Describe and compare value types and reference types. Write programs that use variables.
Classes, Objects, Arrays, Collections and Autoboxing Dr. Andrew Wallace PhD BEng(hons) EurIng
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 7 th & 8 th Lecture Pavel Ježek.
.NET Framework & C#.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 11 th Lecture Pavel Ježek
Consuming REST Services from C# SoftUni Team Technical Trainers Software University
How to be a C# ninja in 10 easy steps Benjamin Day.
Jon Shemitz Complicated stuff, quickly..NET 2.0. ● Generics50% & Nullable Types ● Iterators 10% ● Delegate Enhancements35% ● Partial Types5%
Hoang Anh Viet Hà Nội University of Technology Chapter 1. Introduction to C# Programming.
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
Neal Stublen What’s an indexer?  An array has an indexer… int[] myArray = new int[5]; for (int index = 0; index < 5; ++index) {
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
Problems.Net Анатолий Крыжановский Обра. ООП 2 class Bar { } void Foo(object a) { Console.WriteLine("object"); } void Foo(object a, object b) { Console.WriteLine("object,
C Sharp Web & Internet Programming Group Diana, Aren, Jeff, & Adam, Farrin 5/5/20081CS 311.
Bill Campbell, UMB Microsoft's.NET C# and The Common Language Runtime.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College Lecture 2: Working with Visual.
Neal Stublen Tonight’s Agenda  Indexers  Delegates and events  Operator overloading  Class inheritance  Q&A.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 11 th Lecture Pavel Ježek
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Session 02 Module 3: Statements and Operators Module 4: Programming constructs Module 5: Arrays.
Computer Programs CS 1400 Dennis A. Fairclough Version 1.1 CS 1400 Dennis A. Fairclough Version 1.1.
C# Present and Future Marita Paletsou Software Engineer.
Clear Lines Consulting · clear-lines.comApril 21, 2010 · 1 The Joy of Pex
Run on Windows.NET as system component Run on VM (CLR) Black box compilers Edit in Visual Studio Proprietary Run everywhere Deploy with app Compile.
5/19/2018 1:01 AM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN.
16: Equals Equals Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Future of C#
Internet and Java Foundations, Programming and Practice
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
Herding Nulls and other C# stories from the future
Implementing Polymorphism
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
null, true, and false are also reserved.
Module 2 Variables, Assignment, and Data Types
C structures and Compilation to IA32
Quiz Points 1 Rules Raise your hand if you know the question
- This slide is intentionally left blank -
03 | Async Programming & Networking Intro
5. OOP OOP © 2003 Microsoft.
Presentation transcript:

10 dingen die je niet wist over C#

ALM ALM Ranger Microsoft Auteur Getrouwd Lezen C#

Junior

Medior

Senior

private static string A(string a, string b, string c) { string result = "{a:" + a + ", b:" + b + ", c:" + c + "}"; return result; } private static string B(string a, string b, string c) { StringBuilder sb = new StringBuilder(100); string result = sb.Append("{a:").Append(a).Append(", b:").Append(b).Append(", c:").Append(c).Append("}").ToString(); return result; } A B A&B

Ja Nee static void Main() { CapitalLetters(null); } static IEnumerable CapitalLetters(string input) { if (input == null) { throw new ArgumentNullException(input); } foreach (char c in input) { yield return char.ToUpper(c); }

var result = from i in new List { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } select i; foreach (var r in result) Console.Write(r); // Displays Compiler bug Extension methods IL rewriting

class keyword var a = "dev"; var b = " Net "; var c = "Noord"; Console.WriteLine(a + b + c); // Displays devNetNoord Wat is var hier?

public class HomeController : Controller { public async Task Index() { var pi = await Task.Run (Helper.CalculatePi(1000)); return View(pi); } asynchroon synchroon

private async static Task Run() { await A(); // A takes 1 second await B(); // B takes 2 seconds } 1 2 3

1 Ja Nee static List cache; void Run() { if (cache == null) { cache = FetchItems(); } // work with cache }

static void Main() { int n = 0; var up = Task.Run(() => { for (int i = 0; i < ; i++) n++; }); for (int i = 0; i < ; i++) n--; up.Wait(); Console.WriteLine(n); } < 0 0 > 0

static void Foo () where T : new() { T t = new T(); Console.WriteLine("ToString: " + t.ToString()); Console.WriteLine("GetHashCode: " + t.GetHashCode()); Console.WriteLine("Equals: " + t.Equals(t)); Console.WriteLine("GetType: " + t.GetType()); } Foo

static void Foo () where T : new() { A: T t = new T(); B: Console.WriteLine("ToString: " + t.ToString()); C: Console.WriteLine("GetHashCode: " + t.GetHashCode()); D: Console.WriteLine("Equals: " + t.Equals(t)); E: Console.WriteLine("GetType: " + t.GetType()); } A B C D E

class Base { public virtual void Foo(int x) { Console.WriteLine("Base.Foo(int)"); } class Derived : Base { public override void Foo(int x) { Console.WriteLine("Derived.Foo(int)"); } public void Foo(object o) { Console.WriteLine("Derived.Foo(object)"); } new Derived().Foo(10);

int i1 = ; Ja Nee

int ten = 10; int i2 = ten; Ja Nee

int ten = 10; int i2 = ten; Wat is de uitkomst?

public class Point(int x, int y) { private int x, y; } var bestValue = points?.FirstOrDefault()?.X ?? -1; public double Distance => Math.Sqrt((X * X) + (Y * Y)); public Point Move(int dx, int dy) => new Point(X + dx, Y + dy); Do(someEnum); public void Do(params IEnumerable points ) {... } int.TryParse("123", out int x); var x = new MyClass(1, "X"); public int X { get; } = x;

Tot zover de quiz

Any fool can know The point is to understand

MultithreadingPerformanceSyntactic sugar

Multithreading

Async en await

Async? private async static Task RunCPU() { string content = await Task.Run (() => "Hello devNetNoord!"); return content.Length; } private async static Task RunIO() { HttpClient client = new HttpClient(); string result = await client.GetStringAsync(" return result.Length; }

Platform ClientCPUI/OServerCPUI/O UIThreadThreadPool

Async is niet parallel private async static Task Run() { await A(); // A takes 1 second await B(); // B takes 2 seconds } private async static Task RunParallel() { Task a = A(); // A takes 1 second Task b = B(); // B takes 2 seconds await Task.WhenAll(a, b); }

Performance

Generation 2 objects Generation 1 objects Generation 0 objects Uncommited Commited Allocated Free

Boxing & unboxing

class UnmanagedWrapper : IDisposable { private IntPtr unmanagedBuffer; public FileStream Stream { get; private set; } public UnmanagedWrapper() { CreateBuffer(); this.Stream = File.Open("temp.dat", FileMode.Create); } private void CreateBuffer() { … } ~UnmanagedWrapper() { Dispose(false); } public void Close() { Dispose(); } public void Dispose() { Dispose(true); System.GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { Marshal.FreeHGlobal(unmanagedBuffer); if (disposing) { if (Stream != null) { Stream.Close(); }

using (UnmanagedWrapper u = new UnmanagedWrapper()) { }

Syntactic sugar

C#IL Machine code var numbers = new List { 1, 2, 3, 4 }; init ([0] class [mscorlib] System.Collections. Generic.List`1 numbers, [1] int32 n, [2] class [mscorlib]System.Co llections.Generic.L ist`1 '<>g__initLocal0', [3] valuetype mov ecx, h call FFD2FAC0 mov dword ptr [ebp- 5Ch],eax mov ecx,dword ptr [ebp-5Ch] call 78BFBF90 mov eax,dword ptr [ebp-5Ch] mov dword ptr [ebp- 44h],eax mov ecx,dword ptr [ebp-44h] mov edx,1 cmp dword ptr [ecx],ecx call 78BE24C0

yield async & await foreach using lock Nullable …

ildasm

En nu? John Skeet: C# in Depth Jeffrey Richter: CLR via C# Eric Lippert: Stackoverflow

@wouterdekort