En el archivo .csproj es posible que tengan la siguiente configuración:
<Nullable>enable</Nullable>
En algunas propiedades de la clase Book.cs aparecerá este warning:
CS8618 - Non-nullable variable must contain a non-null value when exiting constructor. Consider declaring it as nullable.
Pueden hacer lo siguiente:
- declarar la propiedad como nullable
public class Book
{
public string? Title { get; set; }
public int PageCount { get; set; }
public string? Status { get; set; }
public DateTime PublishedDate { get; set; }
public string? ThumbnailUrl { get; set; }
public string? ShortDescription { get; set; }
public string[]? Authors { get; set; }
public string[]? Categories { get; set; }
}
- asignarle un valor por default
public class Book
{
public string Title { get; set; } = "";
public int PageCount { get; set; }
public string Status { get; set; } = "";
public DateTime PublishedDate { get; set; }
public string ThumbnailUrl { get; set; } = "";
public string ShortDescription { get; set; } = "";
public string[] Authors { get; set; } = Array.Empty<string>();
public string[] Categories { get; set; } = Array.Empty<string>();
}
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?
o inicia sesión.