下面逻辑最简单的写法是什么

What is the simplest way of writing below logic

我有这样的逻辑。

if( (value1 !="0" || value2!="0") && value3=="0")
{
  value3=string.empty;
}

同样

  if( (value2 !="0" || value3!="0") && value1=="0")
    {
      value1=string.empty;
    }

 if( (value1 !="0" || value3!="0") && value2=="0")
    {
      value2=string.empty;
    }

使用 linq 编写上述逻辑的最佳方法是什么?没有重复逻辑

我的想法是让他们通过 collection 字典。但不太确定逻辑

你可以用一行函数解决这个问题:

bool test(string[] orConds, string andCond, string val) => orConds.Any(s => s != val) && andCond == val;

用法:

const string check = "0";
string s1 = "0", s2 = "1", s3 = "0";

if (test(new[] { s1, s2 }, s3, check))
  s3 = check;