C#: Generic Interface for Numbers

后端 未结 2 1818
难免孤独
难免孤独 2021-01-18 14:07

I am trying to perform some generic number manipulation independent of the number type. However, I know of no way to use generics to do this. The first idea was to filter th

2条回答
  •  滥情空心
    2021-01-18 14:11

    Rewriting is probably easiest. The only other solution I can come up with is to go beyond templates, write a String that represents your function, with placeholder chars for the type, then replace it with each type name and compile it at runtime.

    Apart from the initial performance hit due to compilation it will also be difficult to call these functions.

提交回复
热议问题