【发布时间】:2022-01-01 20:05:35
【问题描述】:
我马上要说 - 我是一个认真的初学者,这是我的学习项目。 我正在尝试制作一种方法,管理员可以搜索满足特定条件的帐户。 首先,系统会提示他输入所有参数,然后我只想使用有一些输入的参数来搜索满足所有条件的帐户。
如果所有参数都有一些输入,这是它搜索数组的部分:
for (int index = 0; index < objAccount.Length; index++)
{
if (objAccount[index].accNum == accNum && objAccount[index].accLogin == accLogin && objAccount[index].accName == accName && objAccount[index].accBalance == accBalance && objAccount[index].accType == accType && objAccount[index].accStatus == accStatus)
{
Console.WriteLine($"{objAccount[index].accNum,15}" + $"{objAccount[index].accLogin,15}" + $"{objAccount[index].accName,20}" + $"{objAccount[index].accBalance,15:C}" + $"{objAccount[index].accType,15}" + $"{objAccount[index].accStatus,15}");
}
}
以我有限的知识,我想出的一个解决方案是对所有参数执行 if/else ifs,但由于我必须对所有组合都这样做,所以很多代码似乎是不必要的。肯定有一种更有效的方法来做到这一点,而我只是没有看到。
有人可以帮我解决这个问题吗?
【问题讨论】:
-
也许不是初学者,但我会为此使用 Linq 表达式树。 (不能给出AFK的示例代码)
标签: c# .net console-application