c# - Reuse the Same Variable For Multiple TryParse() Calls -


i did reading on this, , questions similar mine, looks ask might not (easily) possible... wanted verify anyway. maybe questions older version of c#/.net, , thing has been implemented recently.

anyway. have switch-case statement in 1 of classes, purpose take int (typeid) , string (value) , check whether value can parsed data type indicated typeid. example, here part of have now:

    case 1:         char charret;         return char.tryparse(value, out charret);     case 2:         regex re = new regex(constants.regex_alphanumeric);         return re.ismatch(value);     case 3:         bool boolret;         return bool.tryparse(value, out boolret);     //and on... 

what able avoid char/bool instantiation see in cases 1 & 3. ideally, have return statement. it's not big deal (obviously), nice if make more (even more) compact.

that's inherently impossible.

variables passed out parameters must match parameter type.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -