C#两个依赖布尔变量 [英] C# two dependents boolean variables

查看:88
本文介绍了C#两个依赖布尔变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有循环发送到比较数据的函数并返回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?

推荐答案

我不明白你的问题是什么,但你可能需要像以下这样的函数:

I did not understand clearly what is your problem, but you may need a function like:
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#两个依赖布尔变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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