Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

253
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda