什么呢!Convert.ToBoolean()是什么意思? [英] What does !Convert.ToBoolean() mean?

查看:586
本文介绍了什么呢!Convert.ToBoolean()是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了类似的代码:

 bool [] leds = new bool [3 * 64]; 
int [] audionr = new int [4];
int audiosound;

public int AudioSound
{
get {return audiosound;}
set {audiosound = value;}
}

.... //继续代码
leds [audionr [0]] =!Convert.ToBoolean(this.AudioSound& 0x001);





在这种情况下,这个!Convert.ToBoolean是什么意思?

解决方案

是二元否定运算符。

!true返回false

!false返回true



Convert.ToBoolean(this.AudioSound)生成一个来自int值的boolean值(意思是,如果int值为零则返回false,否则返回true),此代码将 leds 表中的索引零处的布尔值赋值给否定int值的转换 AudioSound



至于为什么这个代码会这样做,这是不可能的回答没有研究算法,并弄清楚如何使用LED表。

!Convert.ToBoolean()意味着它只是否定来自Convert.ToBoolean()的结果

如果Convert.ToBoolean()返回true则转换为!Convert.ToBoolean ()为false,如果Convert.ToBoolean()返回false,那么!Convert.ToBoolean()为true。


I came across a code that looks something like:

bool[] leds = new bool[3*64];
int[] audionr = new int[4];
int audiosound;

public int AudioSound
{
get {return audiosound;}
set {audiosound = value;}
}

....//further on in code
leds[audionr[0]] = !Convert.ToBoolean(this.AudioSound & 0x001);



What does this "!Convert.ToBoolean" do/mean in this scenario?

解决方案

! is the binary negation operator.
!true returns false
!false returns true

Convert.ToBoolean(this.AudioSound) producing a boolean value from an int value (meaning, returns false if int value is zero, otherwise returns true), this code is assigning the boolean value at index zero in leds table to the negation of the conversion of the int value AudioSound.

As to why this code doas that, it's impossible to answer without studying the algorithm and figure out how the leds table is used.


!Convert.ToBoolean() mean that it just negate the result coming from Convert.ToBoolean()
if Convert.ToBoolean() return true then !Convert.ToBoolean() is false and if Convert.ToBoolean() return false then !Convert.ToBoolean() is true.


这篇关于什么呢!Convert.ToBoolean()是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆