带C#示例的String.Equality(==)运算符
C#String.Equality運算符 (C# String.Equality operator )
"==" is a String.Equality operator in C#, it is used to check whether two strings objects have the same values or not.
“ ==”是C#中的String.Equality運算符 ,用于檢查兩個字符串對象是否具有相同的值。
Syntax:
句法:
public static bool operator == (string a, string b);Parameter: It has two parameters both are strings to compare..
參數:它有兩個參數都是要比較的字符串。
Return value: bool – it returns a Boolean value. If strings have the same value, it returns true, else it returns false.
返回值: bool-返回布爾值。 如果字符串具有相同的值,則返回true ,否則返回false 。
Example:
例:
Input:string str1 = "IncludeHelp";string str2 = "IncludeHelp";String.Equality:str1 == str2;Output:trueC#使用String.Equality(==)運算符比較兩個字符串的示例 (C# Example to compare two strings using String.Equality (==) operator )
using System; using System.Text;namespace Test {class Program{static void Main(string[] args){string str1 = "IncludeHelp";string str2 = "IncludeHelp";//comparing stringsConsole.WriteLine("str1==str2: " + (str1 == str2));if (str1 == str2)Console.WriteLine("str1 and str2 have the same values");elseConsole.WriteLine("str1 and str2 don't have the same values");str1 = "Hello world";str2 = "IncludeHelp";//comparing stringsConsole.WriteLine("str1==str2: " + (str1 == str2));if (str1 == str2)Console.WriteLine("str1 and str2 have the same values");elseConsole.WriteLine("str1 and str2 don't have the same values");//hit ENTER to exitConsole.ReadLine();}} }Output
輸出量
str1==str2: True str1 and str2 have the same values str1==str2: False str1 and str2 don't have the same valuesReference: String.Equality(String, String) Operator
參考: String.Equality(String,String)運算符
翻譯自: https://www.includehelp.com/dot-net/string-equality-operator-with-example-in-c-sharp.aspx
總結
以上是生活随笔為你收集整理的带C#示例的String.Equality(==)运算符的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php发展历,PHP的发展历程
- 下一篇: 小写大写转换_小写到大写转换器JavaS