LESSON 58 / 75·2 min readIntermediate

Sorting and searching in C#

Good to knowConcept lesson
01 Understand02 Recall03 Prepare

Sorting

csharp
Array.Sort(arr);
Array.Sort(arr, (a, b) => b.CompareTo(a));
csharp
public int BinarySearch(int[] arr, int target) {
    int left = 0, right = arr.Length - 1;

    while (left <= right) {
        int mid = left + (right - left) / 2;
        if (arr[mid] == target) return mid;
        if (arr[mid] < target) left = mid + 1;
        else right = mid - 1;
    }

    return -1;
}

PAUSE & RECALL

Can you explain it without the notes?

Sorting and searching in C#

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Sorting

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Sliding window and two pointers in C#

Adapted from 17_DSA_DOTNET.md · “11. Sorting and searching in C#”. Examples are study fragments; framework behavior can depend on your version.