Q:

Write a program in C# Sharp to find the strings for a specific minimum length

0

Write a program in C# Sharp to find the strings for a specific minimum length. 
Test Data :
Input number of strings to store in the array :4
Input 4 strings for the array:
Element[0] : this
Element[1] : is
Element[2] : a
Element[3] : string
Input the minimum length of the item you want to find : 5
Expected Output:
The items of minimum 5 characters are :
Item: string

All Answers

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

using System;  
using System.Collections.Generic;  
using System.Linq;  
class  LinqExercise22
    {  
        static void Main(string[] args)  
        {  
            string[] arr1;
            int n,i,ctr;
            Console.Write("\nLINQ : Find the strings for a specific minimum length : "); 
            Console.Write("\n------------------------------------------------------\n");	
		    Console.Write("Input number of strings to  store in the array :");
		    n= Convert.ToInt32(Console.ReadLine()); 
            arr1 =new string[n];      
            Console.Write("\nInput {0} strings for the array  :\n",n);
                for(i=0;i<n;i++)
                {
                Console.Write("Element[{0}] : ",i);
                arr1[i] = Console.ReadLine();	
                }	
		    Console.Write("\nInput the minimum length of the item you want to find : ");
		    ctr = Convert.ToInt32(Console.ReadLine()); 
            IEnumerable<string> objNew = from m in arr1  
                                         where m.Length >= ctr  
                                         orderby m  
                                         select m;  
            Console.Write("\nThe items of minimum {0} characters are : \n",ctr); 
            foreach (string z in objNew)  
                Console.WriteLine("Item: {0}", z);  
  
            Console.ReadLine();    
        }  
    }
  

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