From: Raj on
string str1="rakshith";
if(str1.ToUpper()=="RAKSHITH")
{
//DO SOMETHING
}
Console.WriteLine("str1 value is : " + str1);
//prints as "RAKSHITH


if(UCase(str1)=="RAKSHITH")
{
//DO SOMETHING
}
Console.WriteLine("str1 value is: " + str1);
//prints as rakshith

Seems ToUpper() makes str1 mutable whereas in C# it is not!!

Any help would be appreciated

Thank you

Regards
Raj
From: Patrice on
Hello,

> string str1="rakshith";
> if(str1.ToUpper()=="RAKSHITH")
> {
> //DO SOMETHING
> }
> Console.WriteLine("str1 value is : " + str1);
> //prints as "RAKSHITH

This is not what I'm seeing (it prints "rakshith" as expected). If you have
some code instead of // DO SOMETHING double check you are not altering str1
?...

Also not sure if the issue is VB or C# related. A c# group might be better
as you seems to provide only C# code...

--
Patrice



From: Herfried K. Wagner [MVP] on
Raj schrieb:
> string str1="rakshith";
> if(str1.ToUpper()=="RAKSHITH")
> {
> //DO SOMETHING
> }
> Console.WriteLine("str1 value is : " + str1);
> //prints as "RAKSHITH

.... only if the string variable 'str1' already contains "RAKSHITH".

BTW, I suggest using 'String.Compare' instead of comparing upper-case
values.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
From: Joe Cool on
On Nov 9, 9:02 am, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...(a)gmx.at> wrote:
> Raj schrieb:
>
> > string str1="rakshith";
> > if(str1.ToUpper()=="RAKSHITH")
> > {
> > //DO SOMETHING
> > }
> > Console.WriteLine("str1 value is : " + str1);
> > //prints as "RAKSHITH
>
> ... only if the string variable 'str1' already contains "RAKSHITH".
>
> BTW, I suggest using 'String.Compare' instead of comparing upper-case
> values.
>

Other than the fact that String.Compare exists, is there any other
reason to use it instead of comparing upper (or lower) case values to
determine equality?
From: Joe Cool on
On Nov 9, 11:20 am, Joe Cool <joecool1...(a)live.com> wrote:
> On Nov 9, 9:02 am, "Herfried K. Wagner [MVP]" <hirf-spam-me-
>
>
>
>
>
> h...(a)gmx.at> wrote:
> > Raj schrieb:
>
> > > string str1="rakshith";
> > > if(str1.ToUpper()=="RAKSHITH")
> > > {
> > > //DO SOMETHING
> > > }
> > > Console.WriteLine("str1 value is : " + str1);
> > > //prints as "RAKSHITH
>
> > ... only if the string variable 'str1' already contains "RAKSHITH".
>
> > BTW, I suggest using 'String.Compare' instead of comparing upper-case
> > values.
>
> Other than the fact that String.Compare exists, is there any other
> reason to use it instead of comparing upper (or lower) case values to
> determine equality?

Actually a co-worker reminded me that our staff had talked about this
several months ago. The advantage of using String.Compare is that the
ToUpper and ToLower methods actually create a new string in memory and
the memory is not released until the garbage collector kicks in. So
using String.Compare instead of using ToUpper or ToLower to perform
case-insensitve compares can save on memory.