Variable type question

  • Thread starter Thread starter Andrea Williams
  • Start date Start date
A

Andrea Williams

Is there a way to change the datatype of a return variable inside a
function?

Example:
public static ?XXX? RequestVar(string strValue)
{
return Request.Form[strValue)];
}

The value may be a string, int, long or could even be a boolean.

Thanks,
Andrea
 
Values in the Request.Form Collection are always strings. Your obvious bet
would be to return a string. There is no way that the function or anything
else can guess what data type a string is supposed to represent. However,
the calling function, as it is passing the string representing the form
field that is desired, should know the data type it is looking for, and the
conversion can be made from the calling function.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Back
Top