2020-06-30 12:47:33 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
|
|
|
|
----
|
|
|
|
public int Example(int i)
|
|
|
|
{
|
|
|
|
return (int) (i + 42); // Noncompliant
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerable<int> ExampleCollection(IEnumerable<int> coll)
|
|
|
|
{
|
|
|
|
return coll.Reverse().OfType<int>(); // Noncompliant
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
----
|
|
|
|
public int Example(int i)
|
|
|
|
{
|
|
|
|
return i + 42;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerable<int> ExampleCollection(IEnumerable<int> coll)
|
|
|
|
{
|
|
|
|
return coll.Reverse();
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
== Exceptions
|
|
|
|
|
|
|
|
Issues are not raised against C# 7.1 `default` literal.
|
2020-06-30 14:49:38 +02:00
|
|
|
|
2020-06-30 12:47:33 +02:00
|
|
|
----
|
|
|
|
bool b = (bool)default; // Doesn't raise an issue
|
|
|
|
----
|