I'm trying to learn Ienumerable with linq.
What I want to do is to print the userlist after filtering it with linq. But I am encountering such a console screen.
Main Code:
class Program
{
static void Main(string[] args)
{
LinqExtensions<UserObject> linq = new LinqExtensions<UserObject>();
var users = new List<UserObject>()
{
new UserObject()
{
Id=1,
FirstName="xx",
LastName="yy",
EmailAdress="[email protected]",
CreateDateTime=DateTime.Now
},
new UserObject()
{
Id=2,
FirstName="aa",
LastName="bb",
EmailAdress="[email protected]",
CreateDateTime=DateTime.Now
}
};
var userList = linq.Where_EqualsEvenID(users);
Console.WriteLine(userList);
Console.ReadLine();
}
}
And Extensions Code:
public class LinqExtensions <T> where T:UserObject
{
public IEnumerable<T> Where_EqualsEvenID(IEnumerable<T> TTypeIEnum)
{
return TTypeIEnum.Where(p => p.Id % 2 != 0).ToList();
}
public IEnumerable<T> Where_OddEvenID(IEnumerable<T> TTypeIEnum)
{
return TTypeIEnum.Where(p => p.Id % 2 != 0).ToList();
}
public IEnumerable<T> Where_EqualsId(IEnumerable<T> TTypeIEnum,int id)
{
return TTypeIEnum.Where(p=>p.Id==id).ToList();
}
}
Console Message: System.Collections.Generic.List`1[Linq_1.Objects.UserObject]
Help me please, thanks a lot.
Why are you getting the type text instead of values?
Console.WriteLine(Object)writes the text representation of an object..ToString()method..ToString()default implementation.How to fix your issue?
To fix this issue, you override
ToString()within theUserObjectclass.Now while printing the list of
UserObject, you need to iterate over each object ofUserObjectand print the details.You can also use
string.Join(),This will print