একটি খালি তালিকাতে একটি স্ট্রিং শুরু করতে -
string myStr = null;
এখন, তালিকাটি খালি আছে কিনা তা পরীক্ষা করতে বিল্ট-ইন পদ্ধতি IsNullOrEmpty() ব্যবহার করুন -
if (string.IsNullOrEmpty(myStr)) { Console.WriteLine("String is empty or null!"); }
আসুন সম্পূর্ণ কোডটি দেখি -
উদাহরণ
using System; namespace Demo { class Program { static void Main(string[] args) { string myStr = null; if (string.IsNullOrEmpty(myStr)) { Console.WriteLine("String is empty or null!"); } Console.ReadKey(); } } }
আউটপুট
String is empty or null!
একটি খালি স্ট্রিং একটি স্ট্রিং আরম্ভ করার আরেকটি উপায়, নিম্নলিখিত কোড চেষ্টা করুন. এখানে, আমরা string.Empty −
ব্যবহার করেছিউদাহরণ
using System; namespace Demo { public class Program { public static void Main(string[] args) { string myStr = string.Empty; if (string.IsNullOrEmpty(myStr)) { Console.WriteLine("String is empty or null!"); } else { Console.WriteLine("String isn't empty or null!"); } } } }
আউটপুট
String is empty or null!