list sort()多个条件间的排序

 根据品质、等级进行排序,并把寻宝放在最后面;

品质quality、等级Level、寻宝DoTreasure

List legendCardDataList = new List();
legendCardDataList.Sort(SortByIdTreasureHunt);

int SortByIdTreasureHunt(LegendCardData data1, LegendCardData data2)
{
	ConfigArmyHeroInfo heroInfo1 = ConfigManager.inst.DB_ArmyHero.Get(data1.LegendId);
	ConfigArmyHeroInfo heroInfo2 = ConfigManager.inst.DB_ArmyHero.Get(data2.LegendId);
	if (data2.DoTreasure.CompareTo(data1.DoTreasure) != 0)
	{
		return data1.DoTreasure.CompareTo(data2.DoTreasure);
	}
	if (heroInfo1 != null && heroInfo2 != null)
	{
		if (heroInfo2.quality.CompareTo(heroInfo1.quality) != 0)
		{
			return heroInfo2.quality.CompareTo(heroInfo1.quality);
		}
		else if (data2.Level.CompareTo(data1.Level) != 0)
		{
			return data2.Level.CompareTo(data1.Level);
		}
		else
		{
			return heroInfo2.internalId.CompareTo(heroInfo1.internalId);
		}
	}

	return 1;
}

 

你可能感兴趣的:(C#)