0

what it the meaning of that code

  if (theStatus.ToUpper() == "APPROVE")
                {
                    if (theLinkButtonDownload != null)
                    {
                        theLinkButtonDownload.Visible = true;
                    }
                }

in this what to upper exactly done?

user3044672
  • 65
  • 1
  • 1
  • 8
  • 1
    ToUpper() simply CAPITALIZED all possible capitalizable characters in the string. – Melvin Dec 03 '13 at 02:07
  • Are you looking for something like "it means someone does not know how to use enums" or "I love ALL CAPS"? Or "does it have security issues"? Or something else (assuming you've clicked F1 in VS to get help on the `ToUpper` method already) – Alexei Levenkov Dec 03 '13 at 02:10
  • 2
    Note: a better alternative is to use a string comparison that ignores case when possible. http://stackoverflow.com/questions/6371150/comparing-two-strings-ignoring-case-in-c-sharp – JDwyer Dec 03 '13 at 02:10
  • 1
    Actually, @JDwyer, a better alternative would have been to consult MSDN to see what they have to say instead of asking such a simple question on SO. http://msdn.microsoft.com/en-us/library/system.string.toupper(v=vs.110).aspx – NotMe Dec 03 '13 at 02:23
  • does not display minimal understanding – Neil Thompson Feb 28 '14 at 17:49

3 Answers3

3

1. .ToUpper() returns the string in UPPERCASE.
so that all letters in in your string variable theStatus becomes capital.

basic advantage of using .ToUpper() is while comparing the string if you want to ignore the case (either upper or lower) you can convert the String to Capital using .ToUpper() and then compare with CAPITAL String.

if (theStatus.ToUpper() == "APPROVE")

2. you can achieve same thing by converting your variable theStatus into Lower case and then compare with LowerCase Letters using .ToLower() function.

if (theStatus.ToLower() == "approve")

3. You can do same thing using Equals() Method by passing StringComparison.InvariantCultureIgnoreCase so that while comparing Strings Equals method Ignore the Case and perform Comparision.

Note : here you do not need to compare with either LOWER or UPPER case letters because Equals() just ignore the case and do the Comparison.

1=> if (theStatus.Equals("APPROVE", StringComparison.InvariantCultureIgnoreCase))

2=> if (theStatus.Equals("approve", StringComparison.InvariantCultureIgnoreCase))

3=> if (theStatus.Equals("aPpRoVe", StringComparison.InvariantCultureIgnoreCase))

all of the above cases are true if your theStatus contains approve in any case.

Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67
0

To change the value of theStatus variable to be Upper Case character.

azisfatoni
  • 120
  • 5
0

Please see other guys' answer for what does "ToUpper()" do.

But my suggestion is to define the status in a const variable, and use this variable whenever you set or get the value. So you don't need to care about it's upper or lower case and it's more maintainable.

public class MyStatus
{
        public const string Approve = "Approve";
        public const string Deny = "Deny";
}

//...
if (theStatus == MyStatus.Approve) {...}
Teddy
  • 1,407
  • 10
  • 19