sipi41
Member
- Joined
- Apr 12, 2020
- Messages
- 6
- Programming Experience
- 1-3
Thank you for reading! I'm getting a list of objects (from a dbcontext), then I created a method to pass this list to a Local Function, the method accepts the list but when I try to loop, instead of being able to show the content of my object members I get an error saying: "'T' does not contain a definition for 'Id' and no accessible extension method 'Id' accepting a first argument of type 'T' could be found (are you missing a using directive or an assembly reference?) " And this problem is not only with Id, I can't access any of the properties, please check the code: would you please help me find what I am missing? thank you for your advice.
C#:
public class Fruit
{
public int Id { get; set; }
public string Name { get; set; }
}
public class ImporterController : Controller {
public IActionResult Racks()
{
List<Fruit> Fruits = new List<Fruit> {
new Fruit{Id = 1, Name = "Mango"}
, new Fruit{Id =2, Name="Banana" }
};
ProcessMyList<Fruit>(Fruits);
void ProcessMyList<T>( List<T> list)
{
foreach (T thing in list)
{
Debug.WriteLine(thing.Name); /* LINE CAUSING THE PROBLEM...*/
}
}
return Json("done");
}
}
Attachments
Last edited: