问题描述
我有循环发送到比较数据的函数并返回true \ false(isEqual),然后打印结果。我有布尔变量IsTestpassed,我希望他在第一次函数返回false时包含false ...
我想要输出外观:
true(isEqual )
true(isEqual)
false(isEqual)
true(isEqual)
测试通过: false(第三次更改的IsTestpassed的值执行了该函数)。
总结:我需要IsTestpassed将依赖于isEqual而isEqual为true,这是第一次因为false我想要那个IsTestpassed将保持不变。
我该怎么办?
I have loop that send to function that compare data and return true\false (isEqual), and than print the result. and I have boolean variable IsTestpassed that I want him to contain false at the first time that the function return false...
I want the output look:
true (isEqual)
true (isEqual)
false (isEqual)
true (isEqual)
Is the test passed: false(the value of IsTestpassed that changed for the third time performed the function).
In summary:I need that IsTestpassed will depend on isEqual while isEqual true,at the first time it becames false I want that IsTestpassed will stay false.
How can I do it?
推荐答案
IsTestPassed &= isEqual;
这个方式,每当你的isEqual函数返回false时,这会将IsTestPassed设置为false。
即,IsTestPassed为true的唯一方法是每个isEqual调用都返回true。
我忘了提到这只有在你将IsTestPassed变量初始化为true时才有效。[/ edit]
This way, whenever your isEqual function returns false, this will set IsTestPassed to false.
I.e., the only way for IsTestPassed to be true is that every isEqual call has returned true.
[edit]I forgot to mention that this will only work if you initialize your IsTestPassed variable to true.[/edit]
这篇关于C#两个依赖布尔变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!