This file contains hidden or 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
static void Main() | |
{ | |
MyEvent += Handle; | |
Console.WriteLine("1. Before invoking event"); | |
MyEvent(null, null); | |
Console.WriteLine("3. After invoking event"); | |
Thread.Sleep(1000); | |
} |
This file contains hidden or 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
// Given: | |
var y = ...; | |
{ | |
var x = F(y); | |
G(x); | |
} | |
// After | |
Action action = () => { |
This file contains hidden or 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
const int RetryAttempts = 5; | |
const int RetryIntervalSeconds = 8; | |
static FooResults FooClientExecuteCommand(FooClient client, string command) | |
{ | |
FooResults results = null; | |
for (var i = 0; i <= RetryAttempts; i++) | |
{ | |
try | |
{ |
This file contains hidden or 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
return Win() | |
.DoIfNull(Advantage) | |
.DoIfNull(ScoreNormal) | |
.DoIfNull(ScorePerson1) | |
.DoIfNull(ScorePerson2) | |
.DoIfNull(ScoreTie); |
This file contains hidden or 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
string result = null; | |
if (result == null) | |
result = Win(); | |
if (result == null) | |
result = Advantage(); | |
if (result == null) | |
result = ScoreNormal(); | |
if (result == null) | |
result = ScorePerson1(); | |
if (result == null) |
This file contains hidden or 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
// A primitive | |
string emailAddress = "[email protected]"; | |
// Better | |
class EmailAddress | |
{ | |
public EmailAddress(string value) { this.Value = value; } | |
public string Value { get; } | |
} |
This file contains hidden or 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
class CustomerId | |
{ | |
public CustomerId(string value) | |
{ | |
this.Value = value; | |
} | |
public readonly string Value; | |
public override bool Equals(object obj) |
This file contains hidden or 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
class Point | |
{ | |
public static bool operator==(Point left, Point right) | |
{ | |
return left.Equals(right); | |
} | |
public static bool operator!=(Point left, Point right) | |
{ | |
return left.Equals(right); |
This file contains hidden or 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
class Point | |
{ | |
public static bool operator==(Point left, Point right) | |
{ | |
return left.Equals(right); | |
} | |
} | |
This file contains hidden or 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
class Point | |
{ | |
override bool Equals(object other) | |
{ | |
if (other.GetType() != this.GetType()) return false; | |
return this.X == ((Point)other).X && this.Y == ((Point)other).Y; | |
} | |
} |