|
-
Mar 2nd, 2004, 02:21 PM
#1
Thread Starter
Lively Member
Function Error -C#
Hello Everybody:
I am trying to develop a function to concate three strings . When I compile it gives me a runtime error .Can anyone tell me whats wrong?
The error is :
public string Variable(string UserName, string PhoneNumber, string RemoteYN)
{
txtUserName.Text=UserName ;
txtPhoneNumber.Text=PhoneNumber;
txtRemoteString.Text=RemoteYN ;
// Variable;
return Variable(UserName,PhoneNumber,RemoteYN);
}
private void cmdOutPut_Click(object sender, System.EventArgs e)
{ txtOutput.Text= Variable(UserName,PhoneNumber,RemoteYN);
txtOutput.Text = txtUserName.Text + " " + txtPhoneNumber.Text + " " + txtRemoteString.Text;
}
The run time error is : System.StackOverflowException' occurred in system.windows.forms.dll
Pls guide...
Rahil
-
Mar 2nd, 2004, 03:02 PM
#2
looks like you need to be using a void not a string for Variable , eg:
VB Code:
public void Variable(string UserName, string PhoneNumber, string RemoteYN)
{
string strResult = string.Empty; // initialize the string
strResult +=UserName + " " ;
strResult +=PhoneNumber + " ";
strResult +=RemoteYN ;
txtOutput.Text = strResult;
}
private void cmdOutPut_Click(object sender, System.EventArgs e)
{
Variable(txtUserName.Text,txtPhoneNumber.Text,txtRemoteString.Text);
}
this line ...
return Variable(UserName,PhoneNumber,RemoteYN);
will be causing the error , because you are trying to return part of the calling string.
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Mar 2nd, 2004, 04:15 PM
#3
Frenzied Member
Try using the StringBuilder class, because everytime you concatenate strings it is creating a new instance of the string.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Mar 2nd, 2004, 07:50 PM
#4
Frenzied Member
why not
Code:
return string1 + string2 + string3;
or
Code:
string s = "";
s += string1;
s += string2;
s += string3;
return s;
Magiaus
If I helped give me some points.
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
|