c# - 结构类型的扩展方法
问题描述
我有这两个重复的方法作为扩展方法,但我想把它们浓缩成一个扩展方法,
我曾想过使用约束: where T : Struct ,
但是那么 bool ,其他结构类型呢,有没有办法只限制 int decimal float long 等。
public static bool IsBetween(this double value, double lowerBound, double upperBound)
{
return value >= lowerBound && value <= upperBound;
}
public static bool IsBetween(this decimal value, decimal lowerBound, decimal upperBound)
{
return value >= lowerBound && value <= upperBound;
}
解决方案
推荐阅读
- python - 使用列表列表在 pandas 中创建 DataFrame
- reactjs - 在 ReactJS 中将 props 传递给组件
- c# - C# OrderBy 方法如何按包含哈士奇代码的字符对对象进行排序?
- java - 尝试创建一个活动,当单击字体按钮时,fontfamily 应该更改
- reactjs - 如何解决“无效的 Hook Call”?
- html - 使用 HTML 时标记为属性指定值而不为属性指定名称的结果是什么?见描述中的例子
- java - 同时使用 2 个用户界面(GUI 和控制台)中断 Scanner.readLine 调用
- java - 如何在过滤器中从数据库中获取用户并在 jwt 响应中添加 ID?
- python - python中的有序排列
- python - 运行此程序时,我不断收到此错误。我已经尝试了我能想到的一切,但仍然无法正常工作