none
How to write only IF statement using wild cards in c#.net ? RRS feed

  • Question

  • string testval = null;
    
    testval = Convert.ToBoolean(testval) ? testval = "YES" : testval = "no";
     The Above Statement worked for IF Else. But i just to write same thing for only IF Statement.
    Thursday, February 11, 2016 10:11 AM

Answers

All replies

  • You haven't explained what you want that code to do.  What it does id the following:

    If 'testval' is "True", it will be changed to "YES", if 'testval' is "False" or null, it will be changed to "no", otherwise, Convert.ToBoolean will throw an exception.

    If that is not what you want, please explain.

    • Edited by Blackwood Thursday, February 11, 2016 1:17 PM
    Thursday, February 11, 2016 1:17 PM
  • Thanks Blackwood. Please find more information

    testval = Convert.ToBoolean(testval) ? testval = "YES" : testval = "no";

    The above statement worked for below logic

    testval = Convert.ToBoolean(testval) ? testval = "YES" : testval = "no";
    
    if(testval==testval)
    {
    testval="YES";
    }
    else
    {
    testval="no";
    }

    So i just want to write same wild card logic for IF not for any IF-Else

    if(testval==testval)
    {
    testval="YES";
    }

    Friday, February 12, 2016 6:01 AM
  • Can you describe the problem not in C#, but in natural language, such as “If the testval string is ‘True’, then replace it with ‘YES’, otherwise keep it unchanged”? Is this what you want?


    • Edited by Viorel_MVP Friday, February 12, 2016 8:53 AM
    Friday, February 12, 2016 8:14 AM
  • Sorry maruthi, but I can't figure out what you're even asking.

    You do realise that "(testval==testval)" will always be true unless testval is null? (Null values have a special rule - any comparison with a null value will give a false result). Perhaps this is where you are getting confused?


    Friday, February 12, 2016 8:48 AM
  • yes Viorel. I dont want to keep any else 

    Friday, February 12, 2016 8:50 AM
  • if (Convert.ToBoolean(testval))
    {
      testval = "YES";
    }
    
    Like this?
    Friday, February 12, 2016 9:08 AM