I am trying to understand the Null Forgiving Operator. I read the docs page on it and am left wondering if it can be used on properties. Say I have the following class:
public class Note
{
public long NoteId { get; set; }
public string NoteText { get; set; }
public long SectionId { get; set; }
}
I am getting a warning saying:
CS8618: Non-nullable property 'NoteText' must contain a non-null value when exiting the constructor. Consider declaring the property as nullable.
I don't want the property to be nullable. But I also don't need a constructor. This class is a Data Transfer Object (DTO) and is only ever passed in to my service or is constructed via AutoMapper.
I had hopped to use the Null Forgiving Operator here, but I can't seem to place it in a way that it will work. (Oddly, Visual Studio will not even let me type it before or after the NoteText property name.)
My guess is that Null Forgiving is just not intended to be used like this.
But I thought I would ask, can the Null Forgiving Operator be used on Automatic Properties?