如果bool为true且数组长度不等于27或数组值25为空,则该方法应返回false。
如果bool为false且数组长度不等于28或者数组值26为空,则该方法也应返回false
private static bool IsValid(string[] values, bool isFullFile)
{
if (isFullFile && (values.Length != 27 || values[24] == string.Empty))
{
return false;
}
if (!isFullFile && (values.Length != 28 || values[25] == string.Empty))
{
return false;
}
return true;
}
这可以简化到足以使用Expression body definition
private static bool IsValid(string[] values, bool isFullFile)
=> isFullFile
? (values.Length == 27 && values[24] != string.Empty)
: (values.Length == 28 && values[25] != string.Empty);
(原谅我回答这个,因为这真的属于代码审查。)