কম্পিউটার টিউটোরিয়াল

C#-এ orderby কীওয়ার্ড

LINQ কোয়েরি সিনট্যাক্সে orderby কীওয়ার্ড ব্যবহার করে কালেকশন সাজানো যায়। ডিফল্ট আপসর্টিং (ascending), নিচের দিকে সাজাতে descending লিখতে হয়।

উদাহরণ

using System;
using System.Collections.Generic;
using System.Linq;

class Demo {
    static void Main() {
        List myList = new List { "truck", "bus", "bicycle", "motorbike" };
        
        // আপসর্টিং (লম্বায় অনুযায়ী)
        var asc = from e in myList orderby e.Length select e;
        Console.WriteLine("Ascending order...");
        foreach (var s in asc) Console.WriteLine(s);
        
        // ডাউনসর্টিং
        var desc = from e in myList orderby e.Length descending select e;
        Console.WriteLine("Descending order...");
        foreach (var s in desc) Console.WriteLine(s);
    }
}

আউটপুট

Ascending order...
bus
truck
bicycle
motorbike
Descending order...
motorbike
bicycle
truck
bus
  1. C#-এ কোয়ান্টিফায়ার (Quantifiers)

  2. C#-এ static কিওয়ার্ড

  3. C#-এ abstract কীওয়ার্ড

  4. C#-এ 'this' কীওয়ার্ড