Monday 15 March 2010

c# - How to return variable datatypes from a method -


I have a method whose callers need different datatapes. I can put all callers in callers and repeat the necessary changes a dozen times, but it seems more efficient in doing this once called method.

  public string myMethod (String myArg) {return DoSomething (myArg); } Public Int32 myMethod (String MyAg) {Return Convert toInt32 (DoSomething (myArg)); } Private string dooming (key) {return some list [key]; }  

If I have several ways that pull data from some of the Lists and use different data types, then I have to convert one type in each example sessions variable or query or form request or There can be a number of other things

I can say

  function myMethod (as myArg string) as variant myMethod = DoSomething (myArg) termination Function  

Sorry, original post too many Was not clear. I hope that will understand more than that.

Thanks

  public T MyMethod & lt; T & gt; (String MyRG) {// work here}  

USAGE

  PublicTime Muthoot & lt; T & gt; (String myArg) {Return (T) Convert. Change Type (Dozometing (MyArg), Typef (T)); }  

Maybe be a little engineered;)


No comments:

Post a Comment