Domanda

I have a boolean variable, and depending on this variable I want to order an array.

So I have two lists:

string[] radiant_players = new string[5];
string[] dire_players = new string[5];

and a boolean radiant_wins.

I want to make an array which orders these lists depending on whether radiant won or not, so:

string[][] games = new string[2][]
games[radiant_wins]=radiant_players;
games[!radiant_wins]=dire_players;

Right now I have radiant_wins as an integer taking values 0 and 1, but I want to use this sort of boolean structure so that I can access the two possible values.

(also, for some reason the % 2 operator isn't working?)

È stato utile?

Soluzione

Something like:

games[radiant_wins==0 ? 0:1] = radiant_players;
games[radiant_wins==1 ? 0:1] = dire_players;

Altri suggerimenti

Given that radiant_wins is a bool, this will have the desired effect:

bool radiant_wins;
games[radiant_wins ? 1 : 0] = radiant_players;
games[radiant_wins ? 0 : 1] = dire_players;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top