I’ve got an object containing 30 properties that I know the names of. The properties are called “ValueX” (1-30) where X is a number.
How would I call value1 – value30 in a loop?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The following will select all of the properties/values into a IEnumerable of an anonymous type that contains name/value pairs for the properties you are interested in. It makes the assumption that the properties are public and that you are accessing from a method of the object. If the properties aren’t public you’ll need to use BindingFlags to indicate that you want nonpublic properties. If from outside the object, replace
thiswith the object of interest.