How to check if IEnumerable is null or empty?

前端 未结 22 1028
梦如初夏
梦如初夏 2020-11-27 12:33

I love string.IsNullOrEmpty method. I\'d love to have something that would allow the same functionality for IEnumerable. Is there such? Maybe some collection he

22条回答
  •  失恋的感觉
    2020-11-27 13:29

    I used simple if to check for it

    check out my solution

    foreach (Pet pet in v.Pets)
    {
        if (pet == null)
        {
            Console.WriteLine(" No pet");// enumerator is empty
            break;
        }
        Console.WriteLine("  {0}", pet.Name);
    }
    

提交回复
热议问题