- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# String Operators
There are two string operators in C#: Equality and Inequality.
Example
Let us see an example of 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); } }
Output
Is string1 null or empty? = False Is string2 null or empty? = False False
Example
Let us now see an example of 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); } }
Output
Is string1 null or empty? = False Is string2 null or empty? = False Is str1 not equal to str2? = False
Advertisements