Cuts away all null values from String array - CSharp System

CSharp examples for System:Array Null Element

Description

Cuts away all null values from String array

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from  w  w w.  j a v a 2 s  .c o m*/

public class Main{
        /// <summary>
      /// Cuts away all null values
      /// </summary>
      public static void PruneStrings(ref string[] arr)
      {
         var list = new List<string>(arr.Length);
         foreach (var obj in arr)
         {
            if (!string.IsNullOrEmpty(obj))
            {
               list.Add(obj);
            }
         }
         arr = list.ToArray();
      }
}

Related Tutorials