C#에는 Equality 및 Inequality의 두 가지 문자열 연산자가 있습니다.
예시
Equality operator −
의 예를 살펴보겠습니다.using System; public class Demo { public static void Main() { string str1 = "Amit"; string str2 = " "; Console.WriteLine("Is string1 null or empty? = "+string.IsNullOrEmpty(str1)); Console.WriteLine("Is string2 null or empty? = "+string.IsNullOrEmpty(str2)); Console.WriteLine("Is string1 equal to str2? = "+str1 == str2); } }
출력
Is string1 null or empty? = False Is string2 null or empty? = False False
예시
이제 C# Inequality operator −
의 예를 살펴보겠습니다.using System; public class Demo { public static void Main() { string str1 = "abcdef"; string str2 = "abcdef"; Console.WriteLine("Is string1 null or empty? = "+string.IsNullOrEmpty(str1)); Console.WriteLine("Is string2 null or empty? = "+string.IsNullOrEmpty(str2)); bool val = str1 != str2; Console.WriteLine("Is str1 not equal to str2? = "+val); } }
출력
Is string1 null or empty? = False Is string2 null or empty? = False Is str1 not equal to str2? = False