问个数组问题
我有数组str[0]="12",str[1]="34",str[2]="",str[3]="56",str[4]="78",str[5]="",str[6]="",str[7]="90"请问如果去掉空数组项,形成新的数组str[0]="12",str[1]="34",str[2]="56",str[3]="78",str[4]="90"
如果解决?谢谢
using System; using System.Collections.Generic; using System.Text; namespace arraytest1 { class Program { static void Main(string[] args) { string[] str = {"12","34","","56","78","","","90"}; int i = 0; foreach (string temp in str) if (!"".Equals(temp)) str[i++] = temp; for(;i<str.Length;i++) str[i] = ""; foreach (string temp in str) Console.Write(temp.Equals("")?"\"\" ":temp.ToString()+" "); Console.ReadKey(); } } }