可以使用以下方法:

  1. 使用Count属性:
List<string> myList = new List<string>();
if(myList.Count > 0)
{
    // List不为空
}
  1. 使用Any方法:
List<string> myList = new List<string>();
if(myList.Any())
{
    // List不为空
}
  1. 使用Null条件运算符:
List<string> myList = new List<string>();
if(myList?.Count > 0)
{
    // List不为空
}
C#判断Liststring不为空

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

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