We use arrays to hold more than 1 values at programming languages. For this reason, we need a lot of array methods like counting items. There is a simple method to find how many items an array has out:
string strArray = new string; strArray = "a"; strArray = "b"; strArray = "c"; strArray = "d"; int result = strArray.Length;
result variable takes 50. This is the number that shows how many values the array can hold but we need how many values the array actually hold? We need 4 instead of 50.
Here is the code for our purpose:
int result = strArray.Count(s => s != null);
If you use integer array, It would be:
int? intArray = new int?; intArray = 5; intArray = 15; int result2 = intArray.Count(i => i.HasValue);