المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Problem with list with generic filter predicate.



C# Programming
03-11-2010, 03:37 PM
Consider this example that works:
List list = new List(){"1","2","a","b"};
list = list.FindAll(delegate(String s)
{
if (s != "a")
{ return false; }
return true;
});
I can't understand why we can't do this :

List list = (from c in oq select c).ToList();
list = list.FindAll(delegate(T o)
{
if (o.GetType().GetProperty("PropertyName").GetValue(o,null).ToString() != company)
{ return false; }
return true;
});
The 'propertyName' is a property that exists in the objects naturally.
This compiles fine but throws an object null reference exception...


Thank you for time...