How to check if an item has already been entered in a list in C #

-3
  • Classes list exists
  • Within this list I put class objects
  • Each object has (string) nameTurma.Text & a numerical value (int) numericUpDown1.Value
  • I use the addTurma method to place the objects in the groups list

        public static List<turma> turmas = new List<turma>();
    
        public static void addTurma(turma x)
        {
    
            turmas.Add(x);
    
        }
     turma x = new turma(nomeTurma.Text,(int)numericUpDown1.Value);
     //Se nomeTurma.Text não exite na lista turmas
      {
      turma.addTurma(x);
      }
    
  • I just want to add class-type objects that do not have the same name, ie verify that stringTurma.Text already exists in the / strong>

        
    asked by anonymous 29.07.2017 / 21:22

    1 answer

    1
    if(turmas.Any(t => t.Text == text))  
    {
    
    }
    
        
    01.08.2017 / 02:57