Does C# have IsNullOrEmpty for List/IEnumerable?

前端 未结 10 517
一生所求
一生所求 2020-12-23 11:04

I know generally empty List is more prefer than NULL. But I am going to return NULL, for mainly two reasons

  1. I have to check and handle null values explicitly,
10条回答
  •  猫巷女王i
    2020-12-23 11:37

    As everyone else has said, nothing is built into the framework, but if you are using Castle then Castle.Core.Internal has it.

    using Castle.Core.Internal;
    
    namespace PhoneNumbers
    {
        public class PhoneNumberService : IPhoneNumberService
        {
            public void ConsolidateNumbers(Account accountRequest)
            {
                if (accountRequest.Addresses.IsNullOrEmpty()) // Addresses is List
                {
                    return;
                }
                ...
    

提交回复
热议问题