简体   繁体   English

C#代码段的作用是什么?

[英]What does this snippet of C# code do?

What does result.IsVisible equal? 结果是什么?可见是相等的吗?

    if(a==b)
        result.IsVisible = obj1.status.abc_REPORT == 'Y'
            && obj1.AnotherValue.ToBoolean() == false;

That depends on the values of obj1.status.abc_Report and obj1.AnotherValue.ToBoolean() (and it all depends on whether a==b or not). 这取决于obj1.status.abc_Reportobj1.AnotherValue.ToBoolean()的值(并且都取决于是否a == b)。

I'm not quite sure of what the real question is here - which bit is confusing you? 我不确定真正的问题是什么-哪一点让您感到困惑?

One bit which may be confusing you is the shortcircuiting && operator (and possibly the lack of bracing!) 可能会使您感到困惑的是&&运算符短路(并且可能缺少支撑!)

The && operator will only evaluate its right hand side if the left hand side evaluates to true : and the overall result of the expression is true if and only if both sides evaluates to true . 如果左边的计算结果为&&运营商将评估其右侧true :和表达的总体结果是true当且仅当双方的计算结果为true (I'm assuming no strange user-defined conversions here.) (我假设这里没有奇怪的用户定义转换。)

So another way of writing it would be: 因此,另一种书写方式是:

if (a == b)
{
    bool visibility = false;
    if (obj1.status.abc_REPORT == 'Y')
    {
        if (obj1.AnotherValue.ToBoolean() == false)
        {
            visibility = true;
        }
    }
    result.IsVisible = visibility;
}

Note that a condition comparing Booleans, like this: 请注意,条件比较布尔值,如下所示:

obj1.AnotherValue.ToBoolean() == false

would usually be written like this: 通常是这样写的:

!obj1.AnotherValue.ToBoolean()

(Note the exclamation mark at the start - the logical "not" operator.) (请注意开头的感叹号-逻辑“非”运算符。)

The same as this, in many less lines: 与此相同,但少了几行:

if (a==b) {
    if (obj1.status.abc_REPORT == 'Y') {
         if (obj1.AnotherValue.ToBoolean() == false) {
             result.IsVisible = true;
         }
         else {
             result.IsVisible = false;
         }
    }
    else {
        result.IsVisible = false;
    }
}

In simple words: 简单来说:

If a is equal to b: 如果a等于b:

result will be visible only if: 结果仅在以下情况下可见:

object1's status's abc_report is Yes(Y = Yes most probably) AND object1's other value cannot be converted to a Boolean object1的状态abc_report为Yes(Y =很有可能是Yes)AND object1的其他值不能转换为布尔值

I'm guess result.IsVisible is a boolean 我猜是结果。IsVisible是一个布尔值

It will be true if the following conditions are true: obj1.status.abc_REPORT == 'Y' and obj1.AnotherValue.ToBoolean() == false 如果满足以下条件,则为true:obj1.status.abc_REPORT =='Y'和obj1.AnotherValue.ToBoolean()== false

Also, a == b must be true to enter the initial if 同样,a == b必须为true才能输入初始

lets go line by line: 让我们逐行:

  if(a==b)

obvious if value of a equals value of b the execute following line 如果a的值等于b的值,则执行下一行很明显

 result.IsVisible = obj1.status.abc_REPORT == 'Y'
        && obj1.AnotherValue.ToBoolean() == false;

result is some object (maybe winforms controls etc) which has a property IsVisible set it to true if obj1.status.abc_REPORT is equal to 'Y' and also obj1.AnotherValue.ToBoolean() is equal to false; 结果是某个对象(可能是winforms控件等),其对象具有IsVisible属性,如果obj1.status.abc_REPORT等于'Y'并且obj1.AnotherValue.ToBoolean()等于false,则将其设置为true;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM