我如何检查一个数字是正的或负的c# ?
当前回答
num < 0 // number is negative
其他回答
你们这些年轻人,还有你们喜欢的"不到"标志。
在我的时代,我们必须使用Math.abs(num) != num //number是负的!
num < 0 // number is negative
if (num < 0) {
//negative
}
if (num > 0) {
//positive
}
if (num == 0) {
//neither positive or negative,
}
或者使用else if
该代码利用SIMD指令来提高性能。
public static bool IsPositive(int n)
{
var v = new Vector<int>(n);
var result = Vector.GreaterThanAll(v, Vector<int>.Zero);
return result;
}
当然没有人给出正确答案,
num != 0 // num is positive *or* negative!
推荐文章
- c# XML文档网站链接
- 如何从日期时间获得完整的月份名称
- 在c#中创建一个对象的副本
- 通过字符串获取c#动态属性的值
- 我如何检查一个数字是正的或负的c# ?
- 无法找到testhost.dll。请发布测试项目并重试
- 什么是indexoutofraneexception / argumentoutofraneexception,我如何修复它?
- DbEntityValidationException -我如何容易地告诉是什么导致了错误?
- 嵌套等待平行。ForEach
- 我如何执行插入和返回插入的身份与Dapper?
- 如何从c#窗体返回一个值?
- 转换JSON字符串到c#对象
- Try /catch +使用,语法正确
- 在using块的中间返回
- 找到未使用的代码