How can I find if particular index in a list is Empty ?

Gunjan Arora 41 Reputation points
2022-02-21T18:58:49.173+00:00

Hi Folks,

public class RowDefinition
{
public List<string>ColumnValues { get; }
public int Length => ColumnValues.Count;

    public RowDefinition( List<string> columnValues)
    {
        ColumnValues = columnValues;
    }
}

I have below list
List<string> obj = new List<string>();
obj.Add("");
obj.Add("");
obj.Add("oop");
List<string> obj1 = new List<string>();
obj1.Add("");
obj1.Add("der");
obj1.Add("oop");
List<string> obj2 = new List<string>();
obj2.Add("");
obj2.Add("der");
obj2.Add("oop");
List<RowDefinition> uuu = new List<RowDefinition>();
uuu.Add(new RowDefinition(obj));
uuu.Add(new RowDefinition(obj1));
uuu.Add(new RowDefinition(obj2));

How can I find if particular index in the list is empty ?
For example if I consider the above table
index[0] is empty as all three list have empty entries at 0 position

Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. P a u l 10,761 Reputation points
    2022-02-21T19:08:12.127+00:00

    If you want to check if the zero'th element of every list is an empty string you could use .All():

    bool isEmpty = uuu.All(list => list.ColumnValues[0] == "");
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.