C# 检查物料 A 和 B 是否为空并提示
以下是示例代码:
foreach (var material in new[] { 'A', 'B', 'C' })
{
switch (material)
{
case 'A':
if (string.IsNullOrEmpty(materialA))
{
Console.WriteLine('料A为空');
}
break;
case 'B':
if (string.IsNullOrEmpty(materialB))
{
Console.WriteLine('料B为空');
}
break;
case 'C':
// 处理料C
break;
}
}
if (string.IsNullOrEmpty(materialA) && string.IsNullOrEmpty(materialB))
{
Console.WriteLine('料A和料B为空');
}
在此示例中,我们使用了一个字符串数组来表示需要处理的物料。然后,我们使用 foreach 循环来遍历每个物料。对于每个物料,我们使用一个 switch 语句来检查它是哪种物料(A、B 或 C)。如果是 A 或 B,我们检查相应的变量是否为空或 null,并在必要时输出一条消息。对于 C,我们可以执行任何必要的处理。最后,如果 A 和 B 都为空,我们输出一条提示消息。
原文地址: https://www.cveoy.top/t/topic/mpVr 著作权归作者所有。请勿转载和采集!