[RESOLVED] Uppercase first letter
Can someone tells me what's wrong with my code:
Code:
protected string CapFirstLetter(string sentence)
{
sentence = char.ToUpper(sentence[0]) + sentence.Substring(1);
return sentence;
}
Then I call CapFirstLetter(Mytextbox.text)
It never prints the first letter upper case.
Re: Uppercase first letter
The code for your method is fine it's the way you're invoking it.
Using CapFirstLetter(Mytextbox.Text) doesn't do anything because you've passed the value of the text to the method not a reference to the value.
Try this:
MyTextBox.Text = CapFirstLetter(MyTextbox.Text)
Re: Uppercase first letter
Is there a way to modify my method so that it will use reference?
Re: Uppercase first letter
Normally yes, you can be tagging your parameter with the ref keyword. But I believe that C# doesn't allow you to pass properties by reference (VB does I think). But you don't need to just change your statement from a method call to an assignment like I suggested and you should be fine.
Re: Uppercase first letter
Thank you. I guess I can live with that :)