
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Logical Operators on String in C#
The following are the logical operators that you can use on Strings in C#.
Operator | Description | Example |
---|---|---|
&& | Called Logical AND operator. If both the operands are non zero then condition becomes true. | (A && B) is false. |
|| | Called Logical OR Operator. If any of the two operands is non zero then condition becomes true. | (A || B) is true. |
! | Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. | !(A && B) is true. |
Let us see an example showing how to use logical AND operator on strings −
Example
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public class Demo { public bool CheckUnique(string str) { string one = ""; string two = ""; for (int i = 0; i < str.Length; i++) { one = str.Substring(i, 1); for (int j = 0; j < str.Length; j++) { two = str.Substring(j, 1); if ((one == two) && (i != j)) return false; } } return true; } static void Main(string[] args) { Demo d = new Demo(); bool b = d.CheckUnique("amit"); Console.WriteLine(b); Console.ReadKey(); } }
Output
True
Advertisements