Q:

Write a C# Sharp program to count the number of strings with given length in given array of strings

0

Write a C# Sharp program to count the number of strings with given length in given array of strings

Sample Output:

Number of Strings: 
3

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace exercises
{
   class Program
    {       
        static void Main(string[] args)
        { 
		   Console.WriteLine("Number of Strings: ");               
           Console.WriteLine(test(new[] {"a", "b", "bb", "c", "ccc" }, 1)); 
        }                  
        static int test(string[] arr_str, int len)
         {
           int ctr = 0;

            for (int i = 0; i < arr_str.Length; i++)
            {
                if (arr_str[i].Length == len) ctr++;
            }
            return ctr;
        }    
    } 
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now