Compilation error with nullable parameter in Razor markup

I declared a Razor page with an optional parameter: [Parameter] public KeyValuePair<string, T>? Value { get; set; } Which I use in the Razor page markup: @if (Value != null && item.Key == Value.Key) { <span> ….. </span> } Visual Studio complains with the nullable type declared with "?" (if I remove the "?", there’s… Read More Compilation error with nullable parameter in Razor markup

Returning null for a nullable enum not allowed

I’ve written a simple extension method to help parse a string to a nullable enum type. public static TEnum? ParseNullableEnum<TEnum>(this string? str) where TEnum : Enum { if (str is null) { return null; } if (!Enum.TryParse(typeof(TEnum), str, ignoreCase: true, out var source)) { throw new ArgumentOutOfRangeException(nameof(str), str, null); } return (TEnum)source; } As you… Read More Returning null for a nullable enum not allowed

Field '_areas' should be initialized because its type 'List<Area>' doesn't allow null

Flutter shows error Non-nullable instance field ‘_areas’ must be initialized. Maybe this is because of not defining null in lists areas what when defining null Like List? _areas; it shows an error on the index Error: Field ‘_areas’ should be initialized because its type ‘List’ doesn’t allow null. Error Line: List _areas; Here is my… Read More Field '_areas' should be initialized because its type 'List<Area>' doesn't allow null

set MySqlParameter = -1 if null

I am trying to use SQL queries, but I meet a problem with nullable objects : Here is my code where I define all MySql parameters : MySqlParameter[] listParams = new MySqlParameter[] { new MySqlParameter("id", this.ID), new MySqlParameter("idStock", this.idStock), new MySqlParameter("certificate", this.certificate), new MySqlParameter("idLO", this.launchingOrder.ID), new MySqlParameter("idToleOri", this.toleOri.ID), new MySqlParameter("idTolesOri", string.Join("+", this.idTolesOri)), new MySqlParameter("listInstructions", string.Join("|",… Read More set MySqlParameter = -1 if null