Easier way of writing null or empty?

前端 未结 5 390
失恋的感觉
失恋的感觉 2020-11-29 12:22

I\'m sure I\'ve missed something here. With a certain project I need to check if a string is empty or null.

Is there an easier way of writing this?

i         


        
5条回答
  •  野性不改
    2020-11-29 12:47

    If you are on .NET 4, you can use

    if(string.IsNullOrWhiteSpace(myString)){
    
    }
    

    else:

    if(string.IsNullOrEmpty(myString)){
    
    }
    

提交回复
热议问题