-3

How to check if a list is not empty?

if (serialNumbersList.Any())     //c# expression equivalent
{
// do stuff
}
Nesto
  • 177
  • 2
  • 5
  • 6
    (sorry, but - have you heard of _search engines_?) Does this answer your question? [Check if an array is empty or exists](https://stackoverflow.com/questions/11743392/check-if-an-array-is-empty-or-exists) – Franz Gleichmann Dec 22 '20 at 10:33
  • afaik, javascript does not have lists, but arrays. But .net and c# do have both arrays and lists. @FranzGleichmann Likely OP didnt know enough javascript to link their question to arrays. – Cleptus Dec 22 '20 at 10:36
  • @Cleptus that is true, but since javascript is, well... javascript, the distinction is practically without meaning. – Franz Gleichmann Dec 22 '20 at 10:41
  • @FranzGleichmann I was commenting the posibility that OP could have done some searching but failed because of not searching using the correct terms. The "_have you heard of search engines_" is a bit rude imho. – Cleptus Dec 22 '20 at 10:44
  • I am writing code in mvc razorpages. I can use c# and JS there but sometimes i cannot connect those two langs. I didnt know JS doesnt have Lists :) – Nesto Dec 22 '20 at 11:15

1 Answers1

1

In javascript there are no lists but arrays, and you can check their length property

if(serialNumberList.length > 0) { 
    // Do your stuff
}
Cleptus
  • 3,446
  • 4
  • 28
  • 34
Karan Talwar
  • 108
  • 6