Getting rid of null/empty string values in a C# array

前端 未结 5 1497
自闭症患者
自闭症患者 2020-12-14 06:40

I have a program where an array gets its data using string.Split(char[] delimiter). (using \';\' as delimiter.)

Some of the values, though, are null. I.e. the string

5条回答
  •  感情败类
    2020-12-14 07:23

    public static string[] nullLessArray(string[] src)
    {
        Array.Sort(src);
        Array.Reverse(src);
        int index = Array.IndexOf(src, null);
    
        string[] outputArray = new string[index];
    
        for (int counter = 0; counter < index; counter++)
        {
           outputArray[counter] = src[counter];
        }
    
        return outputArray;
    }
    

提交回复
热议问题