📄 3.1.txt
字号:
Listing 3.1 Using the Compare Method in the String Class
using System;
namespace _1_UsingStrings
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string string1 = “”;
String string2 = “”;
Console.Write( “Enter string 1: “ );
string1 = Console.ReadLine();
Console.Write( “Enter string 2: “ );
string2 = Console.ReadLine();
// string and String are the same types
Console.WriteLine( “string1 is a {0}\nstring2 is a {1}”,
string1.GetType().FullName, string2.GetType().FullName );
CompareStrings( string1, string2 );
}
public static void CompareStrings( string str1, string str2 )
{
int compare = String.Compare( str1, str2 );
if( compare == 0 )
{
Console.WriteLine( “The strings {0} and {1} are the same.\n”,
str1, str2 );
}
else if( compare < 0 )
{
Console.WriteLine( “The string {0} is less than {1}”,
str1, str2 );
}
else if( compare > 0 )
{
Console.WriteLine( “The string {0} is greater than {1}”,
str1, str2 );
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -