Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MVP Showcase 2015 - C#

864 views

Published on

MVP Showcase 2015 - C#

Published in: Software
  • Be the first to comment

MVP Showcase 2015 - C#

  1. 1. Independent Experts – Real World AnswersIndependent Experts – Real World Answers Microsoft MVP Showcase 22 Abril 2015 C#Paulo Morgado .NET / C#
  2. 2. Independent Experts – Real World AnswersIndependent Experts – Real World Answers Social Responsability MicrosoftMVPShowcase 22Abril2015 “OS DOUTORES PALHAÇOS LEVAM ALEGRIA ÀS CRIANÇAS HOSPITALIZADAS EM PORTUGAL” http://www.narizvermelho.pt/
  3. 3. Independent Experts – Real World Answers Paulo Morgado .NET / C# PauloMorgado
  4. 4. Independent Experts – Real World AnswersIndependent Experts – Real World Answers
  5. 5. Independent Experts – Real World Answers
  6. 6. Independent Experts – Real World AnswersIndependent Experts – Real World Answers
  7. 7. Independent Experts – Real World Answers
  8. 8. Independent Experts – Real World AnswersIndependent Experts – Real World Answers
  9. 9. Independent Experts – Real World Answers
  10. 10. Independent Experts – Real World AnswersIndependent Experts – Real World Answers
  11. 11. Independent Experts – Real World Answers
  12. 12. Independent Experts – Real World AnswersIndependent Experts – Real World Answers Foo(); var task = FooAsync(); From the method signature (how people call it) void Foo() { for (int i=0; i<100; i++) Math.Sin(i); } From the method implementation (what resources it uses) async Task FooAsync() { await client.DownloadAsync(); }
  13. 13. Independent Experts – Real World AnswersIndependent Experts – Real World Answers Is this true for your async methods?
  14. 14. Independent Experts – Real World Answers
  15. 15. Independent Experts – Real World AnswersIndependent Experts – Real World Answers synchronous block the current thread asynchronous without spawning new threads
  16. 16. Independent Experts – Real World AnswersIndependent Experts – Real World Answers void Foo() { FooAsync().Wait(); } -- will deadlock!!!
  17. 17. Independent Experts – Real World Answers
  18. 18. Independent Experts – Real World AnswersIndependent Experts – Real World Answers
  19. 19. Independent Experts – Real World Answers
  20. 20. Independent Experts – Real World AnswersIndependent Experts – Real World Answers
  21. 21. Independent Experts – Real World Answers
  22. 22. Independent Experts – Real World AnswersIndependent Experts – Real World Answers
  23. 23. Independent Experts – Real World AnswersIndependent Experts – Real World Answers
  24. 24. Independent Experts – Real World AnswersIndependent Experts – Real World Answers
  25. 25. Independent Experts – Real World Answers
  26. 26. Independent Experts – Real World AnswersIndependent Experts – Real World Answers
  27. 27. Independent Experts – Real World Answers
  28. 28. Independent Experts – Real World AnswersIndependent Experts – Real World Answers
  29. 29. Independent Experts – Real World Answers
  30. 30. Independent Experts – Real World AnswersIndependent Experts – Real World Answers public class Customer { public string First { get; set; } = "Jane"; public string Last { get; set; } = "Doe"; }
  31. 31. Independent Experts – Real World AnswersIndependent Experts – Real World Answers public class Customer { public string Name { get; }; public Customer(string first, string last) { Name = first + " " + last; } } public class Customer { public string First { get } = "Jane"; public string Last { get; } = "Doe"; }
  32. 32. Independent Experts – Real World AnswersIndependent Experts – Real World Answers public Point Move(int dx, int dy) => new Point(x + dx, y + dy); public static Complex operator +(Complex a, Complex b) => a.Add(b); public static implicit operator string (Person p) => p.First + " " + p.Last; public void Print() => Console.WriteLine(First + " " + Last);
  33. 33. Independent Experts – Real World AnswersIndependent Experts – Real World Answers public string Name => First + " " + Last; public Customer this[long id] => store.LookupCustomer(id);
  34. 34. Independent Experts – Real World AnswersIndependent Experts – Real World Answers using static System.Console; using static System.Math; using static System.DayOfWeek; class Program { static void Main() { WriteLine(Sqrt(3 * 3 + 4 * 4)); WriteLine(Friday - Monday); } }
  35. 35. Independent Experts – Real World AnswersIndependent Experts – Real World Answers using static System.Linq.Enumerable; // The type, not the namespace class Program { static void Main() { var range = Range(5, 17); // Ok: not extension var odd = Where(range, i => i % 2 == 1); // Error, not in scope var even = range.Where(i => i % 2 == 0); // Ok } }
  36. 36. Independent Experts – Real World AnswersIndependent Experts – Real World Answers int? length = customers?.Length; // null if customers is null Customer first = customers?[0]; // null if customers is null int length = customers?.Length ?? 0; // 0 if customers is null int? first = customers?[0].Orders?.Count(); // can be chained PropertyChanged?.Invoke(this, args); // delegate invokation
  37. 37. Independent Experts – Real World AnswersIndependent Experts – Real World Answers var s = $"{p.Name} is {p.Age} year{{s}} old"; var s = $"{p.Name,20} is {p.Age:D3} year{{s}} old"; var s = $"{p.Name} is {p.Age} year{(p.Age == 1 ? "" : "s")} old";
  38. 38. Independent Experts – Real World AnswersIndependent Experts – Real World Answers if (x == null) throw new ArgumentNullException(nameof(x)); WriteLine(nameof(person.Address.ZipCode)); // prints "ZipCode"
  39. 39. Independent Experts – Real World AnswersIndependent Experts – Real World Answers var numbers = new Dictionary<int, string> { [7] = "seven", [9] = "nine", [13] = "thirteen" };
  40. 40. Independent Experts – Real World AnswersIndependent Experts – Real World Answers try { … } catch (SqlException e) when (myfilter(e)) { … }
  41. 41. Independent Experts – Real World AnswersIndependent Experts – Real World Answers Resource res = null; try { res = await Resource.OpenAsync(…); // You could do this. … } catch (ResourceException e) { await Resource.LogAsync(res, e); // Now you can do this … } finally { await res?.CloseAsync(); // … and this. }
  42. 42. Independent Experts – Real World AnswersIndependent Experts – Real World Answers
  43. 43. Independent Experts – Real World AnswersIndependent Experts – Real World Answers
  44. 44. Independent Experts – Real World Answers
  45. 45. Independent Experts – Real World AnswersIndependent Experts – Real World Answers
  46. 46. Independent Experts – Real World AnswersIndependent Experts – Real World Answers CompilationUnit ClassDeclaration MethodDeclaration class C { void M() { } }// C ▫ ParameterList Block var tree = CSharpSyntaxTree.ParseText("...");
  47. 47. Independent Experts – Real World AnswersIndependent Experts – Real World Answers CompilationUnit ClassDeclaration class C { MethodDeclaration } EOF void M ParameterList Block ( ) { } class C { void M() { } }// C ▫
  48. 48. Independent Experts – Real World AnswersIndependent Experts – Real World Answers class∙C { ∙∙∙∙void∙M() ∙∙∙∙{ ∙∙∙∙} }// C ▫ CompilationUnit ClassDeclaration class C { MethodDeclaration } EOF void M ParameterList Block ( ) { } SP EOL EOL // C SPx4 SP EOL EOL EOLSPx4 EOL SPx4
  49. 49. Independent Experts – Real World Answers
  50. 50. Independent Experts – Real World AnswersIndependent Experts – Real World Answers http://blogs.msdn.com/b/lucian/archive/2013/11/23/talk-mvp-summit-async-best-practices.aspx http://channel9.msdn.com/Series/Three-Essential-Tips-for-Async/Three-Essential-Tips-For-Async- Introduction http://curah.microsoft.com/45553/asyncawait-general http://curah.microsoft.com/44400/async-and-aspnet
  51. 51. Independent Experts – Real World AnswersIndependent Experts – Real World Answers https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6
  52. 52. Independent Experts – Real World AnswersIndependent Experts – Real World Answers https://github.com/roslyn https://roslyn.codeplex.com/ https://github.com/code-cracker/ https://github.com/dotnetAnalyzers/ https://github.com/icsharpcode/NRefactory/tree/roslyn
  53. 53. Independent Experts – Real World AnswersIndependent Experts – Real World Answers Communities MicrosoftMVPShowcase 22Abril2015
  54. 54. Independent Experts – Real World AnswersIndependent Experts – Real World Answers We <3 love our sponsors ! MicrosoftMVPShowcase 22Abril2015
  55. 55. Independent Experts – Real World AnswersIndependent Experts – Real World Answers

×