## c 连接字符_用于字符比较的C#程序
## c 連接字符
Input characters and compare them using C# program.
輸入字符并使用C#程序進行比較。
Prerequisite: Methods to input a single character in C#
先決條件: 在C#中輸入單個字符的方法
C#代碼比較兩個字符 (C# code to compare two characters)
Here, we are asking for two characters from the user – and checking whether they are the same characters or not?
在這里,我們要求用戶輸入兩個字符-并檢查它們是否相同?
// C# program for character comparison using System; using System.IO; using System.Text;namespace IncludeHelp {class Test{// Main Method static void Main(string[] args){char ch1;char ch2;//input charactersConsole.Write("Enter a character: ");ch1 = Console.ReadLine()[0];Console.Write("Enter another character: ");ch2 = Console.ReadLine()[0];//comparing charactersif (ch1 == ch2)Console.WriteLine("Input characters are the same");elseConsole.WriteLine("Input characters are not the same");//hit ENTER to exit the programConsole.ReadLine();}} }Output
輸出量
First run: Enter a character: A Enter another character: A Input characters are the sameSecond run: Enter a character: A Enter another character: X Input characters are not the sameC#代碼比較字符串中的字符 (C# code to compare characters in a string)
Here, we are asking for a string from the user – and printing only vowels by comparing each character of the string with vowel characters.
在這里,我們要求用戶輸入字符串,并且通過將字符串的每個字符與元音字符進行比較來僅打印元音。
// C# program for character comparison using System; using System.IO; using System.Text;namespace IncludeHelp {class Test{// Main Method static void Main(string[] args){string str;//input stringConsole.Write("Enter a string: ");str = Console.ReadLine();//printing the stringConsole.WriteLine("Input string is {0}", str);//printing vowels Console.WriteLine("Vowels are...");foreach (char ch in str){if (ch == 'A' || ch == 'a' || ch == 'E' || ch == 'e' ||ch == 'I' || ch == 'i' || ch == 'O' || ch == 'o' || ch == 'U' || ch == 'u'){Console.Write(ch);}}//hit ENTER to exit the programConsole.ReadLine();}} }Output
輸出量
Enter a string: IncludeHelp.com Input string is IncludeHelp.com Vowels are... Iueeo翻譯自: https://www.includehelp.com/dot-net/character-comparison-example-in-c-sharp.aspx
## c 連接字符
總結
以上是生活随笔為你收集整理的## c 连接字符_用于字符比较的C#程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: next和hasnext_使用Java中
- 下一篇: 为什么ConcurrentHashMap