I have some classes with a lot of fields I need to check. Its takes so much duplicated code to check each field so I want to iterate through each field.
How can I do it? It doesn't compile.
It should check first middle and last name fields and return false if any are empty. But it doesn't compile.Code:public class Person { // all fields are required private string firstName; private string middleName; private string lastName; public bool IsValid() { foreach(string str in this) { if (str == string.Empty) { return false; } } return true; }
What is the correct syntax?
Thanks.




Reply With Quote