各位大哥,写的代码不能调试,请帮帮忙
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace jihe
{
class Program
{
static void Main(string[] args)
{
List<Racer> racers = new List<Racer>(new Racer[]
{
new Racer("ochen","Rindt","Austria",6),
new Racer("Ayrton","Senan","Brazil",41),
});
Racer[] racer1 =
{
new Racer("Graham","Hill","UK",14),
new Racer("Emerson", "Fittipalde", "Brazil", 14),
new Racer("Mario","Andretti","USA", 12),
new Racer("Michael","Schumacher","Germany",91),
new Racer("Mika","Hakkinen","Finland",20),
new Racer("Nile","Lauda","Austria",25),
new Racer("Alian","Prost","France",51),
};
racers.AddRange(racer1);
racers.Insert(3, new Racer("Phil", "Hill", "USA", 3));
for (int i = 0; i < racers.Count; i++)
{
Console.WriteLine(racers[i]);
}
}
}
public class Racer : IComparable<Racer>,IFormattable
{
private string firstname;
private string lastname;
private string country;
private int wins;
public Racer() : this(String.Empty, string.Empty, string.Empty) { }
public Racer(string firstname, string lastname, string country) : this(firstname, lastname, country, 0) { }
public Racer(string firstname, string lastname, string country, int wins)
{
this.firstname = firstname;
this.lastname = lastname;
this.country = country;
this.wins = wins;
}
public string Firstname { get; set; }
public string Lastname { get; set; }
public string Country { get; set; }
public string Wins { get; set; }
public override string ToString()
{
return string.Format("{0} {1}", Firstname, Lastname);
}
public string ToString(string format, IFormatProvider formatProvider)
{
switch (format.ToUpper())
{
case null:
case "N":
return ToString();
case "F":
return Firstname;
case "L":
return Lastname;
case "W":
return string.Format("{0},Wis{1}", ToString(), Wins);
case "A":
return string.Format("{0},{1} Wins {2}", ToString(), Country, Wins);
default:
throw new FormatException(string.Format(formatProvider, "Format {0} is not supported", format));
}
}
public string ToString(string format)
{
return ToString(format, null);
}
public int CompareTo(Racer other)
{
int compare = this.(other.Lastname);
if (compare == 0)
return this.(other.Firstname);
return compare;
}
}
}
[ 本帖最后由 云鹤 于 2011-7-8 15:33 编辑 ]