Hi, i created a string that returns another string based on other string but what if that string thats based on is "" (nothing) i want to return a messagebox, how can i return a messagebox instead of a string ?
Printable View
Hi, i created a string that returns another string based on other string but what if that string thats based on is "" (nothing) i want to return a messagebox, how can i return a messagebox instead of a string ?
I think this is a very bad idea... Is there any other way you can get around this? Perhaps before calling the method see if the string is "" and then return a messagebox?
like this ??
?? yeah i could do that but theres no way to do it like i said ?Code:string str;
if (str.equals(""))
{
messagebox.show("Error")
}
Well the only problem with that is you need a return type for your method. Since you said it otherwise returns a string im assuming the current return type for the method is string, and if you just show a messagebox your method wont return anything...
But, if the current return type for the method is string, then either that string will contain something or it will contain nothing.
So, if I'm reading this correctly, it will do something if the string is not empty OR show a message box if it is, right?
You could always give the return type of the method as 'object' that way you can return a string or false (if the function is displaying a messagebox itself), for example.
thanks..........i've solve my problem
How did you solve your problem?
Post your resolution please, as it might help others with the same or similiar problem.
Thanks. :)
i thought i resolved but im wrong.
Care to elaborate?Quote:
Originally Posted by Pac_741
i got it by myself!! wuuu!
okay here it is:
that the code do its it turn the first character of the ToUpp string.Code:private string ToUpper(string Toupp)
{
string temp = null;
if (Toupp.Equals(""))
{
MessageBox.Show("Error");
}
else
{
temp = Toupp.Substring(0, 1);
return temp.ToUpper() + Toupp.Remove(0, 1);
}
return temp;
}
it turns it into a capitalized leter.