Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

261
Visualizações
Check if none of given strings contains a certain string

I have a list of variables declared for a string value. It is from an external source, there could be 5-10 variables. How do I check if all of them do not contain a certain string ("K.K")? I do not want to check for each such as

public string string_1;
public string string_2;
public string string_3;
...
...
...

if(string_1!= "K.K") //for all the strings for non-array collection
{}
...
...
...
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you know how do get your variables into an array/List

var strings = new List<string>();
strings.Add(string_1);
strings.Add(string_2);
strings.Add(string_3);
...

or

var strings = new List<string>{string_1, string_2, string_3, ...};

or

var strings = new []{string_1, string_2, string_3, ...};

you could e.g. use Linq Any and as filter string.Contains or also string.Equals depending on your needs

if(!strings.Any(s => s.Contains("K.K")))
{
    ...
}

Alternatively to using Equals if you know your strings should all be unique you could also use

var strings = new HashSet<string>();
strings.Add(string_1);
strings.Add(string_2);
strings.Add(string_3);
...

or

var strings = new HashSet<string>{string_1, string_2, string_3, ...};

and then simply check

if(!strings.Contains("K.K"))
{
    ...
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda