C# VS2008

  • Thread starter Thread starter Wndr
  • Start date Start date
W

Wndr

Hi All.
Is there a way to use a variable in the function name?
For example:
tmpName="TEST1";
tmpFuncName="Set"+ tmpName+"Data";
tmpFuncName();
 
Hi All.
Is there a way to use a variable in the function name?
For example:
tmpName="TEST1";
tmpFuncName="Set"+ tmpName+"Data";
tmpFuncName();

You could use reflection to look through the function names and find a
matching one but there's most likely a cleaner way to maintain a list
of possible functions rather than using this brute force method.
Without more details on the application I couldn't suggest another
way.
 
Hi All.
Is there a way to use a variable in the function name?
For example:
tmpName="TEST1";
tmpFuncName="Set"+ tmpName+"Data";
tmpFuncName();

Hi,

The only way you could do something like that is using reflection.
But remember that all method should be association with a type. so in
your code you are assuming that the method represented by the string
tmpFuncName is a member of the class wherer that code exist.
 
Thank you guys.
I added new function with the switch case.

message
Hi All.
Is there a way to use a variable in the function name?
For example:
tmpName="TEST1";
tmpFuncName="Set"+ tmpName+"Data";
tmpFuncName();

Hi,

The only way you could do something like that is using reflection.
But remember that all method should be association with a type. so in
your code you are assuming that the method represented by the string
tmpFuncName is a member of the class wherer that code exist.
 
Back
Top