
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
- Related Questions & Answers
- Logical Operators on String in Python?
- Logical Operators on String in Java
- Logical Operators in C++
- Relational and Logical Operators in C
- Java Logical Operators
- Perl Logical Operators
- Python Logical Operators
- What are the logical operators in C#?
- Written version of Logical operators in C++
- Java Regular expressions Logical operators
- What are Logical Operators in JavaScript?
- Explain the logical operators in DBMS
- What are the logical operators in Java?
- C# String Operators
- What types of logical operators are in javascript?
Advertisements