gpt4 book ai didi

c# - 相关 if 条件由 && 运算符控制

转载 作者:行者123 更新时间:2023-12-02 05:14:25 28 4
gpt4 key购买 nike

我有一个 if 控件,如下所示;

if (Directory.Exists(System.IO.Path.Combine(systemPath, "Reports", companyName))
&& Directory.GetFiles(System.IO.Path.Combine(systemPath, "Reports", companyName),
"*.*", SearchOption.TopDirectoryOnly).Length > 0)

控制的第一部分检查目录是否存在,第二部分控制目录中文件的数量。

由于目录可能不存在,第二部分它可以给出一个异常DirectoryNotFoundException。我也不想嵌套 if 条件(第一个 if 用于目录,第二个 if 用于计算文件)

我的问题是;

“&&”运算符是否在不满足第一个条件的情况下检查第二个条件?

最佳答案

不,它没有看到 here

The conditional-AND operator (&&) performs a logical-AND of its bool operands, but only evaluates its second operand if necessary.

关于c# - 相关 if 条件由 && 运算符控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14891693/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com