Home > Software engineering >  Net 6 nullable not giving warning for all types
Net 6 nullable not giving warning for all types

Time:11-23

Using Net 6's <Nullable>enable</Nullable> I have the class:

public class File {
  public Int32 Id { get; set; }
  public Byte[] Content { get; set; }
  public DateTime Created { get; set; }
  public Guid Key { get; set; }
  public String Name { get; set; }
  
  public FileType FileType { get; set; }
}

Why do I get the warning

Non-nullable property '...' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. 

in all properties but not in:

Int32 Id
DateTime Created
Guid Key

CodePudding user response:

Nullable reference types only affect reference types. Value types can never be null and so there is no need to check or warn against them being null.

  • Related