Note that there are some explanatory texts on larger screens.

plurals
  1. USCharles Mark Carroll
    primarykey
    data
    text
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COI actually don't mind a cast solution. What I will do is design a function that takes a type in as first parameter and once I check the fact that that type can be cast and is in proper range will cast appropriately. As for generics supporting infinite types constraints actually help narrow what they support and I have used constraints successfully in some situations to support a few types that fit the constraint in a clean high performance way. THANKS EVERYONE FOR CONFIRMING THE OTHER WAYS I AM ALREADY DOING THIS ARE BETTER THAN GENERIC WAY IN THIS CONTEXT. Thannnnnnnnnnnnnnnnnks!
      singulars
    2. COMy question was what was a best way to do this USING GENERICS!!!! I was aware of the overload approach and am using that and the 'n discrete functions' approach and the clever (T) (Object) approach which I really liked is a "kind of answer" but not complete since it has perf penalties (though small in this case) and could not even in that example keep numbers too large from blowing up the function.
      singulars
    3. COI considered both the strategies you suggest. In the end even in my example I had overloaded functions internally. But .net has quite a few numeric types and I have similar other examples like this where I am not sure what to do and don't want to do... return (T)(object)RandomNumberLong(min, max); although I will that is quite clever. I wish constraints were more flexible. Actually I think generics were invented to allow us to write say one function that can act on and return many types even though the Collections/Structs/etc. example usages are more common.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload