Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string ToUpper() function with ToString()

Tags:

string

c#

I have used a string in C# where i am using C# in Visual studio 2008. I wanted to convert it to uppercase.

string lowerString = txtCheck.Text;
string upperString = lowerString.ToUpper();

Normally this is how i should have used, But the thing is i didn't get any error when i used it like this

string upperString = lowerString.ToUpper().Tostring();

Now i am confused that ToUpper() is also a function, then how can i use the second syntax where i again use ToUpper().Tostring(); . I mean It would mean Function1().Function2().

like image 553
Nagaraj Tantri Avatar asked Sep 10 '10 01:09

Nagaraj Tantri


1 Answers

No, you're calling ToString on the object returned by ToUpper. This is pointless, but it's not a compilation error. If you did:

lowerString.ToUpper.ToString();

that will indeed give you an error, since you can't call a method (ToString) on a method group.

like image 73
Matthew Flaschen Avatar answered Oct 03 '22 01:10

Matthew Flaschen