2024-11-14 13:25:46 +01:00
|
|
|
include::../description-dotnet.adoc[]
|
2024-11-08 10:08:55 +00:00
|
|
|
|
|
|
|
=== Code examples
|
|
|
|
|
|
|
|
==== Noncompliant code example
|
|
|
|
|
|
|
|
[source,csharp,diff-id=1,diff-type=noncompliant]
|
|
|
|
----
|
|
|
|
var items = new List<int> { 1, 2, 3 };
|
|
|
|
|
|
|
|
int firstItem = items.FirstOrDefault(); // Noncompliant, this implies the collection might be empty, when we know it is not
|
|
|
|
----
|
|
|
|
|
|
|
|
==== Compliant solution
|
|
|
|
|
|
|
|
[source,csharp,diff-id=1,diff-type=compliant]
|
|
|
|
----
|
|
|
|
var items = new List<int> { 1, 2, 3 };
|
|
|
|
|
|
|
|
int firstItem = items.First(); // Compliant
|
|
|
|
----
|
|
|
|
|
2024-11-14 13:25:46 +01:00
|
|
|
include::../resources-dotnet.adoc[]
|
2024-11-08 10:08:55 +00:00
|
|
|
|
|
|
|
include::../rspecator.adoc[]
|