Mid Collections

How can you convert a collection to a different type using LINQ?

Use methods like ToList(), ToArray(), or ToDictionary() to convert LINQ query

results to different collection types.

Examples:

var numbers = new int[] { 1, 2, 3, 4, 5 };

// Convert to List<int>

List<int> numberList = numbers.ToList();

// Convert to array

int[] numberArray = numberList.ToArray();

// Convert to dictionary (key = number, value = square)

Dictionary<int, int> numberDict = numbers.ToDictionary(n => n, n =>

n * n);

Follow:

📘 C# Thread-Safe Collections –

Interview Questions & Answers

More from C# Programming Tutorial

All questions for this course