Given your comments, it sounds like you want the total count of items in each element of the ArrayList
. You can use LINQ for this, although you’ll have to cast each element to a type since you aren’t using the preferred List<T>
type.
return Allfile.Cast<Hashtable>().Sum(c => c.Count);
You should, however, as I commented, switch from ArrayList
to List<T>
, and from Hashtable
to Dictionary<TKey, TValue>
. These types improve everything about your code, particularly in readability and reliability. You would also not need the Cast
function if you changed to a strongly-typed class, like List<T>
.
On the other hand, if you’re just looking for the count of Hashtable
s, you can simply inspect the ArrayList.Count
property:
return Allfile.Count;
5
solved calculate the sum about Hashtable C# [closed]