Wrong value return

Asked

Viewed 30 times

0

I am creating a list within another one as follows:

var playerGames01 = new ObjectGamePlayerMoviments();

        playerGames01.Game = new List<Games>()
        {
           new Games
           {
               PlayerMoviment = new List<PlayersMoviments>()
               {
                    new PlayersMoviments {
                        Name = "Armando",
                        Moviment = "P"
                    },
                    new PlayersMoviments {
                         Name = "Dave",
                        Moviment = "S"
                    }
               }
           }
        };

And when I try to perform a select to find out if there are different movements of P,R ou S, he always returns to me that there is 1.

What am I doing wrong ?

var verifyChoice = game.Game.Select(x => x.PlayerMoviment.Select(y => y.Moviment != "P" && y.Moviment != "S" && y.Moviment != "R"));

It returns as in the image below:

inserir a descrição da imagem aqui

  • Which [is the one that selects?

  • @Maniero put picture in question. The problem is that it returns Empty and consequently takes the value 1, I’m comparing it to 0, if I change the comparison to 1, when I have real value he’ll let it go.

1 answer

0

I managed to solve it this way, in case someone ever needed it.

var verifyChoice = game.Game.Select(x => x.PlayerMoviment.Where(y => y.Moviment != rock && y.Moviment != paper && y.Moviment != scissors)).FirstOrDefault();
  • That was my next question. If you want to filter something, why did you use the Select?

  • 'Cause it’s a list inside a list, with my knowledge I couldn’t find a way to filter the daughter list @Maniero

Browser other questions tagged

You are not signed in. Login or sign up in order to post.