Pass a string to a function

Pass a string to a function

Post by Sammu » Mon, 30 Aug 2004 22:48:05


Hi,

I have the following function to which I need to pass a string variable

private string cMask (string sText)
{

}

but ever time I try to compile I get the error
'test.Form1.cMask(string)': not all code paths return a value

Any idea?
Thanks
Ivan Sammut
 
 
 

Pass a string to a function

Post by Shiv » Mon, 30 Aug 2004 23:00:15

Hi,
Since you have specified this function would return a string, make sure it
does so before completion.
For this specific case, the function doesn't return anything.



Hi,

I have the following function to which I need to pass a string variable

private string cMask (string sText)
{

}

but ever time I try to compile I get the error
'test.Form1.cMask(string)': not all code paths return a value

Any idea?
Thanks
Ivan Sammut

 
 
 

Pass a string to a function

Post by Lukas Than » Mon, 30 Aug 2004 23:06:54

Hi,

that error message means, that your function with return type "string" does
never return a value, so you have to return a string or use void as return
type for your function.

private string cMask (string sText) {
return "Hello World";
}

--- OR ---

private void cMask (string sText) {
dowhateveryouwantornothing();
}


Lukas
 
 
 

Pass a string to a function

Post by UmFrZXNoIF » Tue, 31 Aug 2004 17:39:03

Your method now accepts a string argument, and returns back a string as well.
If you don't want to return anything, change the method declaration to this:

private void cMask (string sText)

Check out this MSDN page for more info on methods
http://www.yqcomputer.com/