I have to process a number of items of data for example
User u = NotMyObject.GetUser(100);
ProcessProperty(u.FirstName);
ProcessProperty(u.Surname);
ProcessProperty(u.Phone.Work);
ProcessProperty(u.Phone.Mobile);
...
ProcessProperty(u.Address.PostCode);
Take it that all properties are returned from GetUser(…) as string. What ProcessProperty does is, I hope, not relevant (maybe write the value to a file, for example) but it would look like:
private void ProcessProperty(string data) {
...
}
My question is given that u.Phone & likewise u.Address may be NULL how can I process the “User u” object without putting each ProcessProperty(…) call in a try/catch block?
Apologies if the formatting of the question is no good, I’m still getting the hang of posting.
Many thanks. N.
You could try (maybe it’s not elegant):
and