Last active
November 16, 2015 14:03
-
-
Save thebentern/8765b164a086a0822a73 to your computer and use it in GitHub Desktop.
C# 6 presentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Old busted | |
private int count = 0; | |
public int Count | |
{ | |
get | |
{ | |
return count; | |
} | |
set | |
{ | |
count = value; | |
} | |
} | |
// New hotness | |
public int Count { get; set; } = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//New hotness | |
Exception exception = null; | |
try | |
{ | |
// Do some foo | |
} | |
catch (Exception ex) | |
{ | |
exception = ex; | |
} | |
if (exception != null) | |
await AsyncLoggingService.Log(ex); | |
//New hotness | |
try | |
{ | |
// Do some foo | |
} | |
catch (Exception ex) | |
{ | |
await AsyncLoggingService.Log(ex); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try | |
{ | |
//do some foo | |
} | |
catch(ApplicationException ex) when(ex.Message == "Bobbeh!") | |
{ | |
WriteToBobbyLog(ex); | |
} | |
catch(ApplicationException ex) when(ex.Message == "Propane") | |
{ | |
WriteToPropaneLog(ex); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Old busted | |
public IEnumerable<int> ListOfNumbers | |
{ | |
get | |
{ | |
return Enumerable.Range(0,100); | |
} | |
} | |
// New hotness | |
public IEnumerable<int> ListOfNumbers => Enumerable.Range(0,100); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Old busted | |
public void MyMethod(MyClass input) | |
{ | |
if(input == null) | |
throw new ArgumentNullException("input"); | |
doThing(); | |
} | |
// New hotness | |
public void MyMethod(MyClass input) | |
{ | |
if(input == null) | |
throw new ArgumentNullException(nameof(input)); | |
doThang(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Old busted | |
int count = 0; | |
if(response != null && response.Results != null) | |
count = response.Results.Count; | |
// New hotness | |
int count = response?.Results?.Count ?? 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string Red = "FF"; | |
public string Green = "99"; | |
public string Blue = "00"; | |
// Old busted | |
public string Color | |
{ | |
get | |
{ | |
return String.Format("{0}{1}{2}", Red, Green, Blue); | |
} | |
} | |
// New hotness | |
public string Color => $"{Red}{Green}{Blue}"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Please don't do this. Use Path.Combine() | |
public string GetMyPath(string category, int id) | |
{ | |
return $@"C:\MyDocuments\{category}\{id}"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Old busted | |
public void DoSomething() | |
{ | |
Console.WriteLine("Swiggity swooty!"); | |
} | |
// New hotness | |
using static System.Console; | |
public void DoSomething() | |
{ | |
WriteLine("Swiggity swooty!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment