⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 4.5.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
Listing 4.5 Sorting Names by Last Name and First Name Using the Compare Method
in the Person Object
using System;
using System.Collections;
namespace _11_Sorting
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string input;
ArrayList alPeople = new ArrayList();
Console.Write( “Enter first and last name or ‘q’ to quit: “ );
input = Console.ReadLine();
// get list of names from user
while( input.Length != 1 || Char.ToUpper(input[0]) != ‘Q’ )
{
string[] name = input.Split( new char[]{‘ ‘}, 2 );
alPeople.Add( new Person( name[0], name[1] ));
Console.Write( “Enter first and last name or ‘q’ to quit: “ );
input = Console.ReadLine();
}
// output unsorted names
Console.WriteLine( “\nArray before sort” );
foreach( Person p in alPeople )
{
Console.WriteLine( “ {0} {1}”, p.firstName, p.lastName );
}
// sort arraylist using custom IComparer
alPeople.Sort( new Person() );
// output sorted array
Console.WriteLine( “\nArray after sort” );
foreach( Person p in alPeople )
{
Console.WriteLine( “ {0} {1}”, p.firstName, p.lastName );
}
}
}
// person definition here...
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -