目次 |
---|
・nullまたは空チェック ・簡単にnullチェック |
using System; class a{ static void Main(){ string str = "abc"; if(string.IsNullOrEmpty(str)) { Console.WriteLine("Null又は空です"); }else{ Console.WriteLine(str); } } }実行結果は以下の通りです。
abc
using System; class a{ static void Main(){ string str1 = null; Console.WriteLine(str1 ?? "not null"); string str2 = ""; Console.WriteLine(str2 ?? "not nullnull"); } }実行結果は以下の通りです。
not null