将布尔值转换为长整数 [英] convert a bool into long
本文介绍了将布尔值转换为长整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将布尔值0和1转换为long
像-0和-1
i try to a bool value 0 and 1 convert in long
like -0 and -1
bool flag=false;
long iApplyTilde = (long) -(flag > false);
请帮助
预先感谢
please help
thanks in advance
推荐答案
您似乎正在尝试根据 flag 的值为字符分配代字号.您为什么要转换为冗长的麻烦?只需在 if 语句中测试 flag 的值,然后采取相应措施即可.如果需要,
It appears that you''re trying to assign a tilde to a character, based upon the value of flag. Why are you going to the trouble of converting to a long? Just test the value of flag in an if statement, and act accordingly. If you must,
long lflag = 0;
if (flag) lflag=1;
long iApplyTilde = lflag;
但我认为没有必要进行所有这些额外工作.
but I see no reason for all that extra work.
第一:-0不存在
first: -0 does noet exist
bool flag = true;
long iApplyTilde = Convert.ToInt64(flag) *-1;
Console.WriteLine(iApplyTilde);
Console.ReadKey(true);
这可能会有所帮助,
It might be helpful,
static void Main(string[] args)
{
Console.WriteLine(GetLongValue(((DateTime.Now.Second % 2) == 0)));
}
private static Int64 GetLongValue(bool flag)
{
return -Convert.ToInt64(flag);
}
参考:
Signed_zero [ ^ ]
浮点规则 [
Ref:
Signed_zero[^]
Floating-Point Rules [^]
:)
这篇关于将布尔值转换为长整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文