作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果您去商店询问“现金还是信用卡?”他们可能会简单地说"is"。当您提出 OR
语句时,这不会告诉您任何信息。 如果(现金||信用)
对于人类来说,他们可能会对这个问题回答“两者”,或“仅{现金 | 信用}”。有没有办法(或运算符)强制 a 语句返回语句的 TRUE 部分?例如:
boolean cash = true;
boolean credit = true;
boolean check = false;
if(cash || credit || check)
{
// In here you would have an array with cash and credit in it because both of those are true
}
我想指出,这不是我想要解决的问题。这是我正在思考的事情,并且想知道这是否可能。我想不出一个实用的应用程序。
最佳答案
在 C# 中,您可以使用带有 Flags 属性集的枚举来执行与此非常类似的操作。
[Flags]
enum MethodOfPayment
{
None = 0,
Cash = 1,
Credit = 2,
Check = 4
}
使用示例:
void Run()
{
MethodOfPayment m = MethodOfPayment.Cash | MethodOfPayment.Credit;
if (m != MethodOfPayment.None)
{
// You can now test m to see which values are selected.
// If you really want the values in an array, you can do this:
MethodOfPayment[] selected = getSelectedValues(m).ToArray();
// selected now contains { Cash, Credit }
}
}
// Helper method to get the selected values from the enum.
IEnumerable<MethodOfPayment> getSelectedValues(MethodOfPayment m)
{
foreach (MethodOfPayment x in Enum.GetValues(typeof(MethodOfPayment)))
{
if ((m & x) != MethodOfPayment.None)
yield return x;
}
}
关于operators - 现金或信用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2821215/
王者人生分享抽10Q币、现金、游戏钻石等 非必中 王者人生分享活动页面给随便一人 即可参与抽奖 奖品有10Q币、现金、游戏钻石等 亲测中10Q币 中了按照步骤兑换即可 活动地址:http:
微博新年许愿DNF抽5Q币+现金 亲测10Q币秒到 速度上 打开微博APP扫码进入活动界面 右上角如果没有红包 就关注并分享 然后在从自己的微博文章入口进入 进入以后再次点击红包 拆红包 红包需
我有个问题困扰了我一段时间。我尝试了一些解决方案,但没有奏效。 我有一个用于现金输入的文本框(例如 $999,99)。但是我需要自动输入“,”和“。”正确显示值。 我尝试了两种解决方案。其中之一是:
#include #include #include int main(void) { // prompt user for "0.00" value float dollars
我是一名优秀的程序员,十分优秀!