Is it possible to declare a method which can return more than one type of variable? I have a method which I am using to cut back on coding time with properties. Instead of getXYZ setXYZ I want to be lazy and use get("XYZ") get("ABC") and set("XYZ", "FOO") set("ABC",
3). I want the get method to return a string in the case of get("XYZ") and an int in the case of get("ABC"). I know that the way to get around this is to use the traditional property naming convntion, however if you have a very large number of properties these
methods, in conjunction with a Hashtable would be a life saver. If it is not possible to return different types from one method, does anyone have any other sugestions? (Other than returning "3" not 3 and using Convert.ToInt()) Thanks, J
You can return an object. That said, this is an ugly solution and will require boxing of value types (like int and double) and really is not the ideal way to do this. A NameValueCollection would allow you to insert and delete things in a collection, though
the names and values would be strings.
jokerdru
Member
5 Points
1 Post
Return Types
Dec 16, 2003 11:21 PM|LINK
douglas.reil...
All-Star
23315 Points
4647 Posts
Re: Return Types
Dec 17, 2003 12:13 AM|LINK
Programming Microsoft Web Forms
My Blog