|
-
Feb 7th, 2010, 02:22 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Set return type of function based on internal variable type
Hi guys!
Another question for you. Hopefully someone knows the answer to this one and is willing to point me in the right direction.
What I have is a function that reads a WMI Query then returns a specific property that is specified in the argument for the function.
What I'd like to do is make the function return the property in it's original type. I don't want to use object because I'd still have to cast it later.
So basically I need a way to make a functions return type the same as the type of the variable. I'm not sure if this can be done with generics or not since I've never used them so pointers would be appreciated.
Thanks everyone!
-
Feb 7th, 2010, 06:46 PM
#2
Re: Set return type of function based on internal variable type
What you're asking for is not possible. Without generics, a functions return type must be set a design time. With generics, a functions return type must be set when you call it. Think about it. If you didn't know what type a function was going to return when you called it, how could you possibly use the result as its own type without a cast anyway? You couldn't declare a variable to assign it to as that type because you don't know what the type is, so you'd still have to assign it to an Object variable anyway.
-
Feb 7th, 2010, 06:48 PM
#3
Thread Starter
Frenzied Member
Re: Set return type of function based on internal variable type
I figured that would probably be the case but I just wanted to be sure. Guess I'll stick with the method I'm using then.
Thanks for the reply.
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
|