I'm in a mess, I have this code:
public class Clase
{
public string Nombre {get; set;}
public Task<List<NombreClase>>? DetalleClase {get, set;}
public Clase() //constructor
{
DetalleClase = new Task<List<NombreClase>>();
}
}
Because what I need is to call it in the console as follows:
public static void Main(string[] args)
{
var clase = New Clase()
{
Nombre = "Ana",
DetalleClase = new Task<List<NombreClase>>
{
new NombreClase
{
Propiedad1 = '',
Propiedad2 = ''
},
new NombreClase
{
Propiedad1 = '',
Propiedad2 = ''
}
}
};
}
But I don't get a favorable response because the VS compiler tells me that Task<List> doesn't have a constructor that takes 0 arguments.
I hope someone can help me, I'm just getting soaked with c#, I'm coming from Vb.NET
I think you have a conceptual error.
Let's say you have a list like this:
Here you have a list containing elements of type "ClassName", to which you assign elements at the time of its instantiation. What I see is that you want to apply the same logic to Task, and your problem is that it is not the same.
An object of type Task references a delegate which in turn references an event or function. That is, Task is "something" that happens not "something" that it contains. Also when you do
Task<algo>
, that "something" is the return of the task, not what the task contains.If you want to wrap your list, so that it is executed asynchronously (since I understand that the code you post is just an example of something bigger that you are doing), you can do something like this: