Get intersection of 2 string arrays

Diego Alvarez 101 Reputation points

Hello. I try to get the intersection of 2 string arrays using an implementation of IEqualityComparer. But for some reason the Equals method is not executed. I put a breakpoint but the execution doesn't stop there. Do you know the reason? Thank you. I attach the code.



An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
8,189 questions
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,086 questions
0 comments No comments
{count} votes

8 answers

Sort by: Most helpful
  1. Andrew Bezkorovayny 6 Reputation points

    @Diego Alvarez your code is working fine for me, too. you can find evidence here:

    1 person found this answer helpful.
    0 comments No comments

  2. LesHay 7,091 Reputation points

    You need to post code in a code block (5th from left in toolbar), unless you expect people here to copy from your image and retype everything.

    Anywat, can't answer your question as I can't view your code. I think it is about getting matches (or differences) in string arrays - if so, check this image out.


    0 comments No comments

  3. Diego Alvarez 101 Reputation points

    Hello LesHay-2099. Thank you for your reply. This is the code:

    if (valoresCondicion.Intersect(numeroOperando.Textos, new ComparadorTextosInformacion(
                                        valorCondicion = true;
    public class ComparadorTextosInformacion : IEqualityComparer<string>
            public TipoOpcionImplicacion_AsignacionTextoInformacion TipoOpcionCondicion_TextosInformacion { get; set; }
            public ComparadorTextosInformacion(TipoOpcionImplicacion_AsignacionTextoInformacion tipoOpcion)
                TipoOpcionCondicion_TextosInformacion = tipoOpcion;
            public bool Equals(string x, string y)
                switch (TipoOpcionCondicion_TextosInformacion)
                    case TipoOpcionImplicacion_AsignacionTextoInformacion.ContengaTexto:
                        return x.Replace("\t", string.Empty).Trim().ToLower().Contains(y.Replace("\t", string.Empty).Trim().ToLower());
                    case TipoOpcionImplicacion_AsignacionTextoInformacion.EmpiecenCon:
                        return x.Replace("\t", string.Empty).Trim().ToLower().StartsWith(y.Replace("\t", string.Empty).Trim().ToLower());
                    case TipoOpcionImplicacion_AsignacionTextoInformacion.TerminenCon:
                        return x.Replace("\t", string.Empty).Trim().ToLower().EndsWith(y.Replace("\t", string.Empty).Trim().ToLower());
                    case TipoOpcionImplicacion_AsignacionTextoInformacion.TextoDistinto:
                    case TipoOpcionImplicacion_AsignacionTextoInformacion.TextoIgual:
                        return x.Replace("\t", string.Empty).Trim().ToLower().Equals(y.Replace("\t", string.Empty).Trim().ToLower());
                return false;
            public int GetHashCode(string obj)
                return obj.GetHashCode();
    0 comments No comments

  4. Andrew Bezkorovayny 6 Reputation points

    Please check the example, the comparer works fine for me, all methods are triggered:

    0 comments No comments

  5. Diego Alvarez 101 Reputation points

    andriyb The code doesn't work for me in my VS project. Will it be a configuration?

    0 comments No comments