একটি স্ট্রিংকে খালি লিস্টে ইনিশিয়ালাইজ করতে:
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!