Write a program in C# Sharp to split a collection of strings into some groups

  • برمجة سي شارب
  • برمجة

Write a program in C# Sharp to split a collection of strings into some groups. 
Expected Output :
Here is the group of cities :

ROME; LONDON; NAIROBI
-- here is a group of cities --

CALIFORNIA; ZURICH; NEW DELHI
-- here is a group of cities --

AMSTERDAM; ABU DHABI; PARIS
-- here is a group of cities --

NEW YORK
-- here is a group of cities --

الأجوبة

using System;
using System.Linq;
using System.Collections.Generic;
class  LinqExercise29
{
static void Main(string[] args)
    {
       string[] cities =  
            {  
                "ROME","LONDON","NAIROBI","CALIFORNIA",
                "ZURICH","NEW DELHI","AMSTERDAM",
                "ABU DHABI", "PARIS","NEW YORK"  
            };   
           Console.Write("\nLINQ : Split a collection of strings into some groups  : "); 
            Console.Write("\n-------------------------------------------------------\n");	
            Console.Write("\nThe cities are : 'ROME','LONDON','NAIROBI','CALIFORNIA','ZURICH','NEW DELHI', \n");
			Console.Write("                   'AMSTERDAM','ABU DHABI','PARIS','NEW YORK' \n");	 
			Console.Write("\nHere is the group of cities : \n\n"); 			
    var citySplit = from i in Enumerable.Range(0, cities.Length)
                                    group cities[i] by i / 3;
    foreach(var city in citySplit)
        cityView(string.Join(";  ", city.ToArray()));
    Console.ReadLine();
    }
static void cityView(string cityMetro)
{
    Console.WriteLine(cityMetro);
    Console.WriteLine("-- here is a group of cities --\n");
}
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...