using System.Collections.Generic;
public static int GetDecimalsCount(decimal[] arrayToSearch, decimal[][] ranges)
if (arrayToSearch == null) throw new ArgumentNullException(nameof(arrayToSearch));
if (ranges == null) throw new ArgumentNullException(nameof(ranges));
if (ranges.Any(x =>x?.Length != 2)) throw new ArgumentException("Invalid ranges",nameof(ranges));
var hashSet = new HashSet<decimal>();
return arrayToSearch.Sum(item =>
public static void Main()
decimal[] ArrayWithFiveElements = {0.1m, 0.2m, 0.3m, 0.4m, 0.5m};
decimal[][] ranges = {new[]{0.1m, 0.2m}, new[]{0.4m, 0.5m}, new[]{decimal.Zero, decimal.One}, };
Console.WriteLine(GetDecimalsCount(ArrayWithFiveElements, ranges));