Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

public class Monkey { public Monkey(int id, string name) { this.id = id; Name = name; } int id; public int Id { get { return id; } } string name; public string Name { get { return name; } set { name = value; } } } public class MonkeyUtils { public static ArrayList GetMonkeys() { ArrayList monkeys = new ArrayList(); monkeys.Add(new Monkey(1, "Sebastian")); monkeys.Add(new Monkey(2, "Sofia")); monkeys.Add(new Monkey(3, "Sofia")); Monkey monkey = (Monkey)monkeys[2]; monkey.Name = "Henry"; return monkeys; } }

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

public partial class Monkey { public Monkey(int? id, string name) { Id = id; Name = name; bool hasValue = Id.HasValue; } int? id; public int? Id { get { return id; } private set { id = value; } } string name; public string Name { get { return name; } set { name = value; } public static class MonkeyUtils { public static List GetMonkeys() { List monkeys = new List(); monkeys.Add(new Monkey(1, "Sebastian")); monkeys.Add(new Monkey(2, "Sofia")); monkeys.Add(new Monkey(3, "Sofia")); Monkey monkey = monkeys[2]; monkey.Name = "Henry"; return monkeys; } }

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

public partial class Monkey { public Monkey(int? id) { Id = id } public Monkey(int? id, string name) { Id = id; Name = name; } public int? Id { get; private set; } public string Name { get; set; } } public static class MonkeyUtils30 { public static List GetMonkeys() { var monkeys = new List { new Monkey(1) { Name = "Sebastian” }, new Monkey(2) { Name = "Sofia” }, new Monkey(3) { Name = "Sofia” }, }; var monkey = monkeys.First(m => m.Id == 3); monkey.Name = "Henry"; monkeys = monkeys.OrderBy(m => m.Name); return monkeys; } }

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

public partial class Monkey { public Monkey(int? id = 0, string name = string.Empty) { Id = id; Name = name; } public int? Id { get; private set; } public string Name { get; set; } } public static class MonkeyUtils { public static List GetMonkeys(bool sort = false) { var monkeys = new List { new Monkey(1) { Name = "Sebastian” }, new Monkey(2) { Name = "Sofia” }, new Monkey(3) { Name = "Sofia” }, }; monkeys.Add(new Monkey(name: "George”)); var monkey = monkeys.First(m => m.Id == 3); monkey.Name = "Henry"; if(sort) monkeys = monkeys.OrderBy(m => m.Name); return monkeys; } public static void Test() { var monkeys1 = GetMonkeys(); var monkeys2 = GetMonkeys(false);//same as above var monkeys3 = GetMonkeys(sort: true); }

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

string GetContentLength(string url) { var request = WebRequest.Create(url); var content= new MemoryStream(); //time to block the UI :( using (var response = request.GetResponse()) { using (var responseStream = response.GetResponseStream()) { responseStream.CopyTo(content); } } return content.Length.ToString(); }

Slide 13

Slide 13 text

async Task GetContentLength(string url) { var request = WebRequest.Create(url); var content = new MemoryStream(); using (var response = await request.GetResponseAsync()) { using (var responseStream = response.GetResponseStream()) { await responseStream.CopyToAsync(content); } } return content.Length.ToString(); }

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; private set; } public string Name { get; set; } public string Location { get; set; } public DayOfWeek MostActiveDay { get { return Id == 0 ? DayOfWeek.Friday : DayOfWeek.Monday; } } public void Print() { Console.WriteLine("We printed some stuff"); } public string DisplayName { get { return string.Format("Monkey {0} lives in {1} with Id of {2}", Name, Location, Id); }

Slide 18

Slide 18 text

public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; private set; } public string Name { get; set; } public string Location { get; set; } public DayOfWeek MostActiveDay { get { return Id == 0 ? DayOfWeek.Friday : DayOfWeek.Monday; } } public void Print() { Console.WriteLine("We printed some stuff"); } public string DisplayName { get { return string.Format("Monkey {0} lives in {1} with Id of {2}", Name, Location, Id); }

Slide 19

Slide 19 text

public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; } public string Name { get; } public string Location { get; set; } public DayOfWeek MostActiveDay { get { return Id == 0 ? DayOfWeek.Friday : DayOfWeek.Monday; } } public void Print() { Console.WriteLine("We printed some stuff"); } public string DisplayName { get { return string.Format("Monkey {0} lives in {1} with Id of {2}", Name, Location, Id); }

Slide 20

Slide 20 text

public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; } = 0; public string Name { get; } = "Sofia"; public string Location { get; set; } = "South America"; public DayOfWeek MostActiveDay { get { return Id == 0 ? DayOfWeek.Friday : DayOfWeek.Monday; } } public void Print() { Console.WriteLine("We printed some stuff"); } public string DisplayName { get { return string.Format("Monkey {0} lives in {1} with Id of {2}", Name, Location, Id); }

Slide 21

Slide 21 text

public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; } = 0; public string Name { get; } = "Sofia"; public string Location { get; set; } = "South America"; public DayOfWeek MostActiveDay { get { return Id == 0 ? DayOfWeek.Friday : DayOfWeek.Monday; } } public void Print() { Console.WriteLine("We printed some stuff"); } public string DisplayName { get { return string.Format("Monkey {0} lives in {1} with Id of {2}",

Slide 22

Slide 22 text

using static System.Console; using static System.DayOfWeek; public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; } = 0; public string Name { get; } = "Sofia"; public string Location { get; set; } = "South America"; public DayOfWeek MostActiveDay { get { return Id == 0 ? Friday : Monday; } } public void Print() { WriteLine("We printed some stuff"); } public string DisplayName { get { return string.Format("Monkey {0} lives in {1} with Id of {2}",

Slide 23

Slide 23 text

using static System.Console; using static System.DayOfWeek; public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; } = 0; public string Name { get; } = "Sofia"; public string Location { get; set; } = "South America"; public DayOfWeek MostActiveDay { get { return Id == 0 ? Friday : Monday; } } public void Print() { WriteLine("We printed some stuff"); } public string DisplayName { get { return string.Format("Monkey {0} lives in {1} with Id of {2}",

Slide 24

Slide 24 text

using static System.Console; using static System.DayOfWeek; public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; } = 0; public string Name { get; } = "Sofia"; public string Location { get; set; } = "South America"; public DayOfWeek MostActiveDay => Id == 0 ? Friday : Monday; public void Print() { WriteLine("We printed some stuff"); } public string DisplayName { get { return string.Format("Monkey {0} lives in {1} with Id of {2}", Name, Location, Id); }

Slide 25

Slide 25 text

using static System.Console; using static System.DayOfWeek; public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; } = 0; public string Name { get; } = "Sofia"; public string Location { get; set; } = "South America"; public DayOfWeek MostActiveDay => Id == 0 ? Friday : Monday; public void Print() { WriteLine("We printed some stuff"); } public string DisplayName { get { return string.Format("Monkey {0} lives in {1} with Id of {2}", Name, Location, Id); }

Slide 26

Slide 26 text

using static System.Console; using static System.DayOfWeek; public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; } = 0; public string Name { get; } = "Sofia"; public string Location { get; set; } = "South America"; public DayOfWeek MostActiveDay => Id == 0 ? Friday : Monday; public void Print() => WriteLine("We printed some stuff"); public string DisplayName { get { return string.Format("Monkey {0} lives in {1} with Id of {2}", Name, Location, Id); } } }

Slide 27

Slide 27 text

using static System.Console; using static System.DayOfWeek; public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; } = 0; public string Name { get; } = "Sofia"; public string Location { get; set; } = "South America"; public DayOfWeek MostActiveDay => Id == 0 ? Friday : Monday; public void Print() => WriteLine("We printed some stuff"); public string DisplayName { get { return string.Format("Monkey {0} lives in {1} with Id of {2}", Name, Location, Id); } } }

Slide 28

Slide 28 text

using static System.Console; using static System.DayOfWeek; public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; } = 0; public string Name { get; } = "Sofia"; public string Location { get; set; } = "South America"; public DayOfWeek MostActiveDay => Id == 0 ? Friday : Monday; public void Print() => WriteLine("We printed some stuff"); public string DisplayName { get { return $"Monkey {Name} lives in {Location} with Id of {Id}"; } } }

Slide 29

Slide 29 text

using static System.Console; using static System.DayOfWeek; public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; } = 0; public string Name { get; } = "Sofia"; public string Location { get; set; } = "South America"; public DayOfWeek MostActiveDay => return Id == 0 ? Friday : Monday; public void Print() => WriteLine("We printed some stuff"); public string DisplayName { get { return $"Monkey {Name} lives in {Location} with Id of " + "{(Id == 0 ? \"Bananas\" : Id)}"; } } }

Slide 30

Slide 30 text

using static System.Console; using static System.DayOfWeek; public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; } = 0; public string Name { get; } = "Sofia"; public string Location { get; set; } = "South America"; public DayOfWeek MostActiveDay => Id == 0 ? Friday : Monday; public void Print() => WriteLine("We printed some stuff"); public string DisplayName => $"Monkey {Name} lives in {Location} with Id of " + "{(Id == 0 ? \"Bananas\" : Id)}"; }

Slide 31

Slide 31 text

using static System.Console; using static System.DayOfWeek; public class Monkey { public Monkey() { } public Monkey(int id, string name, string location) { Id = id; Name = name; Location = location; } public int Id { get; } = 0; public string Name { get; } = "Sofia"; public string Location { get; set; } = "South America"; public DayOfWeek MostActiveDay => Id == 0 ? Friday : Monday; public void Print() => WriteLine("We printed some stuff"); public string DisplayName => $"Monkey {Name} lives in {Location} with Id of " + "{(Id == 0 ? \"Bananas\" : Id)}"; }

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

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 { if (res != null) await res.CloseAsync(); // … and this. }

Slide 34

Slide 34 text

Resource res = null; try { res = await Resource.OpenAsync(…); // You could do this. … } catch(ResourceException e) when (e.Code == 0) { await Resource.LogAsync(res, e); // Now you can do this … } finally { if (res != null) await res.CloseAsync(); // … and this. }

Slide 35

Slide 35 text

Resource res = null; try { res = await Resource.OpenAsync(…); // You could do this. … } catch(ResourceException e) when (myFilter(e)) { await Resource.LogAsync(res, e); // Now you can do this … } finally { if (res != null) await res.CloseAsync(); // … and this. }

Slide 36

Slide 36 text

private static boolLog(Exception e) { /* log it */ ; return false; } … try { … } catch (Exception e) when (Log(e)) { }

Slide 37

Slide 37 text

using System.Linq; IEnumerable range2 = Enumerable.Range(4, 3); IEnumerable squares = range2.Select(x => x * x); foreach (int num in squares) { Console.WriteLine(num); } /* This code produces the following output: 16 25 36 */

Slide 38

Slide 38 text

using static System.Console; using static System.Linq.Enumerable;

Slide 39

Slide 39 text

using static System.Console; using static System.Linq.Enumerable; var range = Range(4, 3); //var squares = Select(range, x => x * x); //Not in scope var squares2 = range.Select(x => x * x); foreach (int num in squares2) { WriteLine(num); }

Slide 40

Slide 40 text

public static void GetMonkey(int count) { if(count < 0) throw new ArgumentNullException("count"); var monkeys = GetMonkeys(); WriteLine("Name: " + monkeys[0].Name); // prints "Name Sofia" }

Slide 41

Slide 41 text

public static void GetMonkey(int count) { if(count < 0) throw new ArgumentNullException(nameof(count)); var monkeys = GetMonkeys(); WriteLine(nameof(monkeys[0].Name) + ": " + monkeys[0].Name); // prints "Name Sofia" }

Slide 42

Slide 42 text

Insights.Report(exception, new Dictionary { {"Some additional info", "foobar"}, {"Name", "James"} } );

Slide 43

Slide 43 text

Insights.Report(exception, new Dictionary { ["Some additional info"] = "foobar", ["Name"] = "James" } );

Slide 44

Slide 44 text

var numbers = new Dictionary { [7] = "seven", [9] = "nine", [13] = "thirteen" };

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

public int Rating { set { if (Subviews == null) return; var star = UIImage.FromBundle("i_star_rate"); for (int i = 0; i < Subviews.Length; i++) { var imageView = Subviews[i] as UIImageView; if (imageView != null) { imageView.Image = (imageView.Tag <= value) ? star : null; } } } }

Slide 47

Slide 47 text

public int Rating { set { if (Subviews == null) return; var star = UIImage.FromBundle("i_star_rate"); for (int i = 0; i < Subviews.Length; i++) { var imageView = Subviews[i] as UIImageView; imageView?.Image = (imageView.Tag <= value) ? star : null; } } }

Slide 48

Slide 48 text

public int Rating { set { var star = UIImage.FromBundle("i_star_rate"); var length = Subviews?.Length; // null var length2 = Subviews?.Length ?? 0; //if length nullable for (int i = 0; i < length; i++) { var imageView = Subviews[i] as UIImageView; imageView?.Image = (imageView.Tag <= value) ? star : null; } } }

Slide 49

Slide 49 text

public void OnPropertyChanged(string name) { var changed = PropertyChanged; if (changed == null) return; changed(this, new PropertyChangedEventArgs(name)); }

Slide 50

Slide 50 text

public void OnPropertyChanged(string name) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); }

Slide 51

Slide 51 text

http://bit.ly/csharp7-proposals

Slide 52

Slide 52 text

Thank you. Questions?