es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

Tag: C#-10.0

¿Por qué el uso de [var x = new T()] se resuelve como [T?]?

Estoy utilizando VS2022, .NET 6, C# 10, con el contexto de nulabilidad habilitado en todo el proyecto. public static ModelEnumerationAttributeProperty FromPropertyInfo(PropertyInfo propertyInfo, object value) { var property = ModelEnumerationAttributeProperty.FromPropertyInfo(propertyInfo); property.PropertyValue = value; property.PropertyValueString = value?.ToString(); return (property); } El tipo auto-detectado de la variable property se resuelve como el tipo . . . Read more

No se puede convertir de ‘System.Collections.IList’ a ‘System.Collections.Generic.IEnumerable‘.

Utilizando C# 10, estoy tratando de convertir un IEnumerable<string>? a un IEnumerable<t>: IEnumerable<string>? inputs = getValues(); if (inputs is null) return false; Type type = typeof(List<>).MakeGenericType(typeof(T)); IList? outputs = (IList?)Activator.CreateInstance(type); TypeConverter converter = TypeDescriptor.GetConverter(typeof(T)); if (converter is null || outputs is null || !converter.CanConvertFrom(typeof(String))) return false; foreach (String input in . . . Read more

Sobrescritura de métodos en un registro heredado.

¿Es el comportamiento esperado con registros en C#10? Console.WriteLine(new Derived1()); // =salida=> Derived1 { } Console.WriteLine(new Derived2()); // =salida=> Base record Base { public override string ToString() => “Base”; } record Derived1 : Base; record Derived2 : Base { public override string ToString() => base.ToString(); }