简体   繁体   English

什么了! 意味着在这种背景下?

[英]What does the ! mean in this context?

button.Click += delegate {
            blue_panel.Visible = !blue_panel.Visible;
        };

What does the '!' 什么是'!' in bluepanel.Visible indicate? 在bluepanel.Visible指示? What does this statement mean and what are alternative ways of writing it? 这句话意味着什么,以及它的替代方式是什么?

The ! 的! symbol is the NOT (or logical negation) operator in C#, see ! symbol是C#中的NOT(或逻辑否定)运算符,请参阅 Operator for more information. 运营商了解更多信息。

In this particular case, it means set the visibility of the blue_panel object to the inverse of what it was previously (true if false, false if true). 在这种特殊情况下,它意味着将blue_panel对象的可见性设置为之前的反转(如果为false则为true,如果为true则为false)。 Essentially its a quick way of toggling a Boolean between its two possible values, commonly used to show/hide things. 基本上它是一种在两个可能值之间切换布尔值的快速方法,通常用于显示/隐藏事物。

There's a few different ways to write it, but why would you want to change it? 有几种不同的方式来编写它,但为什么要改变呢? Its a very concise way of representing a Boolean toggle. 它是一种表示布尔切换的非常简洁的方式。

! is a logical negation operator . 是一个逻辑否定运算符

The logical negation operator (!) is a unary operator that negates its operand. 逻辑否定运算符(!)是一个否定其操作数的一元运算符。 It is defined for bool and returns true if and only if its operand is false. 它是为bool定义的,当且仅当其操作数为false时才返回true。

In your sample, it is toggling the current state of your panel. 在您的示例中,它切换了面板的当前状态。 If it is currently visible than it will be hidden and vice versa. 如果它当前可见,则它将被隐藏,反之亦然。

! is a NOT operator , it makes inverse operasion. 它是一个NOT运算符,它使inverse操作。

So it basically Toggles the state of the blue_panel Visibility. 所以它基本上切换了blue_panel可见性的状态。

Here : 这里 :

blue_panel.Visible = !blue_panel.Visible;  

assigns false if blue_panel is visible , else assign true . 如果blue_panel visible则指定false ,否则指定true

it can be rewritten as : 它可以改写为:

Method 1: 方法1:

if(blue_panel.Visible)
blue_panel.Visible = false;
else
blue_panel.Visible = true;

Method 2: 方法2:

blue_panel.Visible = blue_panel.Visible?false:true;

! usually means not, but in this instance it is used to flip a boolean. 通常意味着没有,但在这种情况下,它用于翻转布尔值。

it says if Visible is true, make it false. 它说如果Visible是真的,那就把它弄错。 If its false make it true. 如果它的错误使其成为现实。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 new()在此上下文中的含义是什么 - What does new() mean in this context 以下配置在WCF的上下文中意味着什么? - What does the following configuration mean in the context of WCF? “=>”是什么意思(在函数/属性上下文中)? - What does '=>' mean (in functions / property context)? “绑定”在 DI 模式的上下文中是什么意思? - What does the `binding` mean in the context of the DI pattern? 在所示的上下文中,“(+ 1超载)”是什么意思? - In the context shown, what does “(+ 1 overload)” mean? 在“.Net Reflection”的背景下,“Emit”是什么意思? - What does “Emit” mean in the context of .Net Reflection? Windows 桌面 (5) 在 .net 5 上下文中是什么意思? - What does Windows Desktop (5) mean in context of .net 5? “上下文”在C#async / await代码中的确切含义是什么? - What does 'context' exactly mean in C# async/await code? ---- s在StringBuilder.ToString()上下文中是什么意思? - What does ----s mean in the context of StringBuilder.ToString()? 在Appsettings.json日志记录上下文中MinimumLevel和Override是什么意思? - What does MinimumLevel and Override mean in appsettings.json logging context?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM