Write a program in C# Sharp to display the list of items in the array according to the length of the string then by name in ascending order

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

Write a program in C# Sharp to display the list of items in the array according to the length of the string then by name in ascending order.

Expected Output :
Here is the arranged list :
ROME
PARIS
LONDON
ZURICH
NAIROBI
ABU DHABI
AMSTERDAM
NEW DELHI
CALIFORNIA

الأجوبة

using System;
using System.Linq;
using System.Collections.Generic;
class  LinqExercise28
{
	static void Main(string[] args)
		{
         string[] cities =  
            {  
                "ROME","LONDON","NAIROBI","CALIFORNIA","ZURICH","NEW DELHI","AMSTERDAM","ABU DHABI", "PARIS"  
            };   
            Console.Write("\nLINQ : Display the list according to the length then by name in ascending order : "); 
            Console.Write("\n--------------------------------------------------------------------------------\n");	
            Console.Write("\nThe cities are : 'ROME','LONDON','NAIROBI','CALIFORNIA','ZURICH','NEW DELHI','AMSTERDAM','ABU DHABI','PARIS' \n");	            
			Console.Write("\nHere is the arranged list :\n");
			IEnumerable<string> cityOrder =
			cities.OrderBy(str => str.Length)
                            .ThenBy(str => str);
			foreach (string city in cityOrder)
				Console.WriteLine(city);    
				Console.ReadLine();
		}
}
هل كان المحتوى مفيد؟

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

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