这是一种可能的C#代码实现,用于判断物料A和物料B是否为空:

// 假设有一个List<string>变量materials存储了物料A、物料B和物料C的值

bool materialAIsEmpty = true;
bool materialBIsEmpty = true;

foreach (string material in materials)
{
    if (material == '物料A')
    {
        materialAIsEmpty = false;
    }
    else if (material == '物料B')
    {
        materialBIsEmpty = false;
    }
}

if (materialAIsEmpty && materialBIsEmpty)
{
    Console.WriteLine('物料A和物料B为空');
}

首先,我们定义了两个bool类型的变量materialAIsEmpty和materialBIsEmpty,初始值都为true。这是为了在循环中判断物料A和物料B是否为空。

然后,我们使用foreach循环遍历List变量materials中的所有物料。在循环中,如果物料是'物料A',则将materialAIsEmpty变量的值设为false;如果物料是'物料B',则将materialBIsEmpty变量的值设为false。

最后,在循环外部判断materialAIsEmpty和materialBIsEmpty变量的值,如果都为true,则输出提示信息“物料A和物料B为空”。

C# 判断物料A和物料B是否为空 - foreach循环示例

原文地址: https://www.cveoy.top/t/topic/mpWD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录