|
-
Dec 9th, 2008, 01:52 PM
#1
Thread Starter
Frenzied Member
[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.
-
Dec 9th, 2008, 01:56 PM
#2
Hyperactive Member
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)
-
Dec 9th, 2008, 01:59 PM
#3
Thread Starter
Frenzied Member
Re: Uppercase first letter
Is there a way to modify my method so that it will use reference?
-
Dec 9th, 2008, 02:08 PM
#4
Hyperactive Member
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.
-
Dec 9th, 2008, 02:15 PM
#5
Thread Starter
Frenzied Member
Re: Uppercase first letter
Thank you. I guess I can live with that
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|