3.1.txt
来自「《Microsoft Visual C# .NET 2003开发技巧大全》源代码」· 文本 代码 · 共 41 行
TXT
41 行
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 + =
减小字号Ctrl + -
显示快捷键?