How do I remove duplicates from a C# array?

后端 未结 27 2674
北海茫月
北海茫月 2020-11-22 07:53

I have been working with a string[] array in C# that gets returned from a function call. I could possibly cast to a Generic collection, but I was w

27条回答
  •  自闭症患者
    2020-11-22 08:47

    NOTE : NOT tested!

    string[] test(string[] myStringArray)
    {
        List myStringList = new List();
        foreach (string s in myStringArray)
        {
            if (!myStringList.Contains(s))
            {
                myStringList.Add(s);
            }
        }
        return myStringList.ToString();
    }
    

    Might do what you need...

    EDIT Argh!!! beaten to it by rob by under a minute!

提交回复
热议问题