1

I have a validation code as follows:

 if ((Info.LENDER_MAIL_STATE == "") || (Info.LENDER_MAIL_CITY == "") || (Info.LENDER_NAME == "") || (Info.LENDER_MAIL_ZIPCODE == 0) || (Info.LENDER_NAME_ID == 0) || (Info.LENDER_TYPE_CODE == "") || (Info.RECORD_ID_CODE == "") || (Info.RECORD_TYPE == "") || (Info.PORPERTY_FIPSCODE == 0) || (Info.RECORDING_PAGE_NUMBER == 0) || (Info.RECORD_ID_CODE == "") || (Info.RECORDING_BOOK_NUMBER == "") || (Info.CONCRNT_MTG_LOAN_TYPE == "") || (Info.DTBORROWER == null) || (Info.RECORDING_DATE == DateTime.MinValue) || (Info.PROPERTY_STATE == "") || (Info.PROPERTY_COUNTY == "") || (Info.PROPERTY_CITY == "") || (Info.PROPERTY_STREET_ADDRESS == "") || (Info.PROPERTY_ZIP == 0) || (Info.DOC_TYPECODE == ""))
            {
                return false;
            }

In this code any of the value is empty it will return false. I need to find out which value is null. Please help. We can achieve this by if else(individual check) that I know, but i need to know the value using this if itself

Saritha.S.R
  • 800
  • 1
  • 6
  • 19

4 Answers4

1

If you want to check the value of a particular variable, then you must use individual if else statement. There might be no way around that.

Although you can use the debugger and check it individually, but I guess for different inputs there might be different results

progrAmmar
  • 2,606
  • 4
  • 29
  • 58
1

You can rearrange your code like:

if ((Info.LENDER_MAIL_STATE == "") ||
    (Info.LENDER_MAIL_CITY == "") ||
    (Info.LENDER_NAME == "") || 
    (Info.LENDER_MAIL_ZIPCODE == 0) ||
    (Info.LENDER_NAME_ID == 0) ||
    (Info.LENDER_TYPE_CODE == "") ||
    (Info.RECORD_ID_CODE == "") ||
    (Info.RECORD_TYPE == "") ||
    (Info.PORPERTY_FIPSCODE == 0)
   .....
{
      return false;
}

This will allow you to step in the debugger.

There is nothing wrong in using else-if construct. The performance will be the same plus this format is better for adding comments.

p.s. Our days the string.IsNullOrWhiteSpace(Info.LENDER_MAIL_STATE) is the recommended function to check the string field.

Kirill Kobelev
  • 10,252
  • 6
  • 30
  • 51
0

You are the best one to find which value is null by debugging the same, instead of == "", check for string.IsNullOrEmpty(Info.LENDER_MAIL_STATE) and so on for each of them. Also check for Info == null is also needed

If you want to find which value is null by code you need to check each field individually if statement is what you can use for that.

Vinay Pandey
  • 8,589
  • 9
  • 36
  • 54
  • would be better to use a string.IsNullOrWhiteSpace() check. – Code Uniquely Oct 09 '13 at 04:46
  • @CodeUniquely, thanks for the comment if someone wonders which one and when to use have a look at http://stackoverflow.com/questions/6976597/string-isnulloremptystring-vs-string-isnullorwhitespacestring – Vinay Pandey Oct 09 '13 at 04:52
  • Yes indeed, I always us it in situations when the input comes from a third party (user, import or data source) as you never know what characters my be in the contents that IsNullOrEmpty misses. – Code Uniquely Oct 09 '13 at 06:10
0

Ooooooops. There is no easy workarounds for what you are asking.

BTW have a look into a SO thread which-condition-is-true-in-an-if-statement.

Any ways my recommendation goes with a client side validation, probably jquery as you and your team are strong enough in the same.

Happy coding days. Cheers dude.

Community
  • 1
  • 1
Praveen Prasannan
  • 7,093
  • 10
  • 50
  • 70