yannip
October 17, 2018, 11:10am
1
Hi all,
Small question: I have a collection and I am trying to check whether the collection is empty.
The name of the collection is “consultants” and is a list of strings.
I tried as followed but then I get an error that the sequence does not contain elements:
Thanks
2 Likes
Divyashreem
(Divyashree Muddagangaiah)
October 17, 2018, 11:16am
2
use Consultants.count>0(this will return you true if your collection is non empty)
7 Likes
Mr_JDavey
(Joshua Davey)
October 17, 2018, 11:16am
3
Hi there @yannip ,
To check whether a collection is null or not populated, you can use the following:
If IsNothing(Consultants) ORELSE Consultants.Count < 1 Then
Else
End If
If, however, you wanted to check whether the collection is null, not populated, or contains only empty values, you can use:
If IsNothing(Consultants) ORELSE Consultants.Count < 1 ORELSE Consultants.AsEnumerable.All(Function (strConsultants) String.IsNullOrWhiteSpace(strConsultants)) Then
Else
End If
Thanks in advance,
Josh
6 Likes
yannip
October 17, 2018, 11:17am
4
thanks @divyashreem and @Mr_JDavey for the quick help. Was indeed what I was looking for.
2 Likes