forum

Home / DeveloperSection / Forums / foreach (where x => x.PROPERTY), how to set PROPERTY?

foreach (where x => x.PROPERTY), how to set PROPERTY?

Anonymous User 2239 19-Aug-2014

I have an Object Student, I get one of the property's values by this method below

System.Reflection.PropertyInfo propValue = typeof(Student).GetProperty(s);

Let's say that s (the string I passed into the GetProperty) was the property called "StudentName". I would then like to run a search based off that property, which was stored in propValue, such as:

foreach (Student stu in formStudents.Where(x => x.propValue == "John"))

However this does not work, as x.__ only fills in with properties of Student (even though valueProp contains a valid property of Student).

How can I override this so that is reads propValue as an actual value of student, or what other method will work for me?

Thank you


c# c# 
Updated on 19-Aug-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By