Count numbers
how we can count numbers in string array using c-sharp ?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jaish MathewsRank #225 · 11K reputationPosted Apr 11, 2010, 8:20 AM EDT
If you are looking for count of "number items" in a ArrayString below logic will help. TryParse() is the method to use.
string[] arr1 = new string[] { "one", "two", "three", "200", "300" };
int num;
int numCount = 0;
foreach (string str in arr1)
{
if (int.TryParse(str, out num))
{
numCount = numCount + 1;
}
}