2
我擁有不同類別的項目集合。 例 -同時對兩個類別進行排序
dogs - Shepherd, Sheepdog, Lapphund
birds - owl, parrot goose
cats - misty , tigger, kitty
我必須將這些存儲在地圖和雙方類別和名稱顯示在升序排列。 預期輸出 -
birds -
owl
goose
parrot
cats -
kitty
misty
tigger
dogs -
Lapphund
Sheepdog
Shepherd
我的代碼 -
class Animal : IComparable{
private string name;
public Animal(string name){
this.name = name;
}
public string Name{
get{
return this.name;
}
set{
this.name = value;
}
}
public int CompareTo(object obj) {
if (obj == null) return 1;
Animal otherAnimal = obj as Animal;
if (otherAnimal != null)
return this.name.CompareTo(otherAnimal.name);
else
return 1;
}
}
,但我也想的類別進行排序,像第一它應該顯示的小鳥,然後貓,然後狗
請問您可以將「Animal」類的定義添加到問題中嗎? –