Pavi S

Pavi S

  • NA
  • 41
  • 74.4k

How to restrict adding null values in list using C#

Jul 28 2012 5:49 AM

my code
---------
string[] array = new string[] { "a", "", null, "d" };
List<string> list = new List<string>();
foreach (string item in array)
   list.Add(item);

actual o/p is
----------------
list[0]="a"
list[1]=""
list[2]=null
list[3]="d"

i want like this
----------------
list[0]=a
list[1]=d

how to restrict null or empty entries adding in the list. please anyone help me.


Answers (3)