楼主:
jamod (jasper)
2015-09-08 18:31:48如题,小弟想要用类似以下做法来做一个工具:
public void StartDelay<T>(Action _action,T _count)where T:int,float
{
if(_count.GetType() == typeof(float))
{
//do something
}
else if(_count.GetType() == typeof(int))
{
//do something
}
}
但是他会跳一个错误,似乎是int和float在where的约束上面会有冲突,
虽然我可以在函式内加一些防呆防止使用者用错,但感觉不是很好=""=
希望能由compiler直接警告使用者,而不是执行到一半才跳错
想请问有没有办法使用where来完成,或是类似的方式?
非常感谢~~
作者: iterator (rotareti) 2015-09-08 18:37:00
你应该要提供 void StartDelay(Action, int)void StartDelay(Action, float)