如何在中使用布尔运算符

时间:2018-10-15 15:38:21

标签: c# operators

我的主要问题是,如何将索引发送给bool运算符? 我尝试在int = 0;类中先做this player.GetPlayer(i++).KA,然后再做PlayerContainer,但是一直都是i = 0
player.GetPlayer(i).KA是玩家的Kills + Assists,如果可以理解的话。

此代码是PlayerContainer.cs类。

class PlayerContainer {
 public Player[] Players;
 public int Count {
  get;
  set;
 }
 public int cycle {
  get;
  set;
 }
 public DateTime date {
  get;
  set;
 }


 public PlayerContainer(int size) {
  Players = new Player[size];
 }
 public void AddPlayer(Player player) {
  Players[Count++] = player;
 }
 public void AddPlayer(Player player, int index) {
  Players[index] = player;
 }
 public Player GetPlayer(int index) {
  return Players[index];
 }
 public static bool operator < (int max, PlayerContainer player) {
  if (max < player.GetPlayer(i++).KA) {
   return true;
  } else
   return false;
 }
 public static bool operator > (int max, PlayerContainer player) {
  int i = 0;
  if (max < player.GetPlayer(i++).KA)
   return true;
  else
   return false;
 }

这在我的Program.cs类的BestBlayer方法中

Player BestPlayer(PlayerContainer AllPlayers) {
 Player player = AllPlayers.GetPlayer(0);
 int max = AllPlayers.GetPlayer(0).KA;
 for (int i = 0; i < AllPlayers.Count; i++) {
  if (max < AllPlayers) {
   max = AllPlayers.GetPlayer(i).KA;
   player = AllPlayers.GetPlayer(i);
  }
 }
 return player;
}

1 个答案:

答案 0 :(得分:0)

Player BestPlayer(PlayerContainer AllPlayers)
{
    Player player;
    int max = AllPlayers.GetPlayer(0).KA;
    Player best = AllPlayers.GetPlayer(0);
    int tmp;
    for (int i = 1; i < AllPlayers.Count; i++)
    {
        tmp = AllPlayers.GetPlayer(i).KA;
        player = AllPlayers.GetPlayer(i);
        if (tmp > AllPlayers)
        {
             max = tmp;
             best = player;
        }
    }
    return best;
  }