使用''或''和'&&'操作者 [英] Using ''or'' and '&&' operator
本文介绍了使用''或''和'&&'操作者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我是C#的新手,有人可以协助您如何最好地编写此代码。场景
Hello,
I am new to C#, can someone please assist on how to best write this code. Scenario
-- If either (Branch , Trainee or Team) values are true
- and (moneydate) within the number of days then'Row.DirectRowToOutput0();'.
DateTime last90Days = DateTime.Now.AddDays(-90);
DateTime last180Days = DateTime.Now.AddDays(-180);
DateTime last365Days = DateTime.Now.AddDays(-365);
If ((
//Branch
row.branchname == "London"
|| row.branchname == "Bristol"
|| row.branchname == "Liverpool"
// Trainee
row.trainee == "trainee1"
|| row.trainee == "trainee2"
|| row.trainee == "trainee3"
//Team
row.team == "team1"
|| row.team == "team2"
|| row.team == "team3"
&& (Row.moenydate < last365Days)
))
{
Row.DirectRowToOutput0();
}
Else if
//Branch
row.branchname == "Oxford"
|| row.branchname == "Leeds"
// Trainee
row.trainee == "trainee4"
//Team
row.team == "team4"
&& (Row.moneydate < last180Days)
))
{
Row.DirectRowToOutput1();
}
}
}
推荐答案
最可读的方式是字面意思几乎所显示的内容:
Most readable way is literally to do pretty much what are are showing:
bool branch = row.branchname == "London" || row.branchname == "Bristol" || row.branchname == "Liverpool";
bool trainee = row.trainee == "trainee1" || row.trainee == "trainee2" || row.trainee == "trainee3";
bool team = row.team == "team1" || row.team == "team2" || row.team == "team3";
if ((branch || trainee || team) && (Row.moneydate < last365Days))
{
Row.DirectRowToOutput0();
}
else
{
branch = row.branchname == "Oxford" || row.branchname == "Leeds";
trainee = row.trainee == "trainee4";
team = row.team == "team4";
if ((branch || trainee || team) && (Row.moneydate < last180Days))
{
row.DirectRowToOutput1();
}
}
这篇关于使用''或''和'&&'操作者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文