Skip to content

Commit

Permalink
Demonstrate better overload resolution inC#8 vs C#7
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-strecker-sonarsource committed Feb 20, 2023
1 parent 2640394 commit 304a702
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ public class Program
public void StringAssertions()
{
var s = "Test";
s.Should(); // Noncompliant (no "ambiguous calls" compiler error as in C# 7)
s?.Should(); // Noncompliant
s?[0].Should(); // Noncompliant
s.Should().Be("Test"); // Compliant
s.Should()?.Be("Test"); // Compliant
s.Should()!?.Be("Test"); // Compliant
}

public void CollectionAssertions()
{
var collection = new[] { "Test", "Test" };
collection.Should(); // Noncompliant (no "ambiguous calls" compiler error as in C# 7)
}

public void DictAssertions()
{
var dict = new Dictionary<string, object>();
Expand Down

0 comments on commit 304a702

Please sign in to comment.