ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Nullability attribute usage with declaration of void or value type

Last modified: 11 February 2024

In the code snippet below, the NotNull annotation is meaningless.

public void SetAge([NotNull] int age)
{
  myAge = age;
}

The reason is that int cannot possibly be null, so any sort of indication that it is or is not null is redundant and can be removed. The same applies to methods that have a void return type.