racer.cs
来自「C#高级编程第6版随书源代码 值得下载」· CS 代码 · 共 77 行
CS
77 行
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wrox.ProCSharp.LINQ
{
[Serializable]
public class Racer : IComparable<Racer>, IFormattable
{
public Racer(string firstName, string lastName, string country, int starts,
int wins)
{
this.FirstName = firstName;
this.LastName = lastName;
this.Country = country;
this.Starts = starts;
this.Wins = wins;
}
public Racer(string firstName, string lastName, string country, int starts)
: this(firstName, lastName, country, starts, 0) { }
public Racer(string firstName, string lastName, string country)
: this(firstName, lastName, country, 0) { }
public Racer(string firstName, string lastName)
: this(firstName, lastName, "unknown") { }
public string FirstName {get; set;}
public string LastName {get; set;}
public int Wins {get; set;}
public string Country {get; set;}
public int Starts {get; set;}
public override string ToString()
{
return FirstName + " " + LastName;
}
public int CompareTo(Racer other)
{
return this.LastName.CompareTo(other.LastName);
}
public string ToString(string format)
{
return ToString(format, null);
}
public string ToString(string format, IFormatProvider formatProvider)
{
switch (format)
{
case null:
case "N":
return ToString();
case "F":
return FirstName;
case "L":
return LastName;
case "A":
return String.Format("{0} {1}, {2}; starts: {3}, wins: {4}",
FirstName, LastName, Country, Starts, Wins);
default:
throw new FormatException(String.Format(
"Format {0} not supported", format));
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?