Practice 50 C# LINQ Programming Questions, TechnoVlogs

Practice 50 C# LINQ Programming Questions


Q1. Write a C# program to find all even numbers from a list of integers using LINQ.  
  Input: numbers = { 1, 2, 3, 4, 5, 6 }  
  Output: 2, 4, 6

Q2. Write a C# program to find all odd numbers from a list of integers using LINQ.  
  Input: numbers = { 1, 2, 3, 4, 5, 6 }  
  Output: 1, 3, 5

Q3. Write a C# program to sort a list of strings alphabetically using LINQ.  
  Input: words = { "apple", "banana", "grape", "kiwi" }  
  Output: apple, banana, grape, kiwi

Q4. Write a C# program to filter a list of numbers greater than 10 using LINQ.  
  Input: numbers = { 5, 12, 3, 17, 8 }  
  Output: 12, 17

Q5. Write a C# program to find the first number that is greater than 10 from a list using LINQ.  
  Input: numbers = { 5, 8, 3, 12, 6 }  
  Output: 12

Q6. Write a C# program to count how many numbers are greater than 5 in a list using LINQ.  
  Input: numbers = { 1, 2, 6, 7, 3, 4, 8 }  
  Output: 4

Q7. Write a C# program to calculate the sum of all numbers in a list using LINQ.  
  Input: numbers = { 1, 2, 3, 4, 5 }  
  Output: 15

Q8. Write a C# program to find the maximum number from a list using LINQ.  
  Input: numbers = { 2, 3, 1, 6, 8, 4 }  
  Output: 8

Q9. Write a C# program to find the minimum number from a list using LINQ.  
  Input: numbers = { 9, 3, 1, 7, 5, 2 }  
  Output: 1

Q10. Write a C# program to check if all numbers in a list are greater than 0 using LINQ.  
   Input: numbers = { 1, 2, 3, 4, 5 }  
   Output: True

Q11. Write a C# program to check if any number in a list is even using LINQ.  
   Input: numbers = { 1, 3, 5, 6, 7 }  
   Output: True

Q12. Write a C# program to group a list of people by their age using LINQ.  
   Input: people = { new Person("Alice", 25), new Person("Bob", 25), new Person("Charlie", 30) }  
   Output: 25: Alice, Bob; 30: Charlie

Q13. Write a C# program to find the first three numbers from a list using LINQ.  
   Input: numbers = { 1, 2, 3, 4, 5 }  
   Output: 1, 2, 3

Q14. Write a C# program to create a list of squared numbers from an existing list using LINQ.  
   Input: numbers = { 1, 2, 3, 4, 5 }  
   Output: 1, 4, 9, 16, 25

Q15. Write a C# program to sort a list of integers in descending order using LINQ.  
   Input: numbers = { 3, 1, 4, 1, 5, 9 }  
   Output: 9, 5, 4, 3, 1, 1

Q16. Write a C# program to get distinct elements from a list using LINQ.  
   Input: numbers = { 1, 2, 3, 1, 2, 4 }  
   Output: 1, 2, 3, 4

Q17. Write a C# program to join two lists of integers using LINQ.  
   Input: numbers1 = { 1, 2, 3 }, numbers2 = { 4, 5, 6 }  
   Output: 1, 2, 3, 4, 5, 6

Q18. Write a C# program to find all words that contain the letter "a" from a list of strings using LINQ.  
   Input: words = { "apple", "banana", "cherry", "date" }  
   Output: apple, banana, date

Q19. Write a C# program to remove all negative numbers from a list using LINQ.  
   Input: numbers = { -1, 2, -3, 4, -5 }  
   Output: 2, 4

Q20. Write a C# program to select all numbers divisible by 3 from a list using LINQ.  
   Input: numbers = { 1, 2, 3, 6, 9, 12, 15 }  
   Output: 3, 6, 9, 12, 15

Q21. Write a C# program to find the average of numbers in a list using LINQ.  
   Input: numbers = { 5, 10, 15, 20, 25 }  
   Output: 15

Q22. Write a C# program to check if a list contains a specific number using LINQ.  
   Input: numbers = { 1, 2, 3, 4, 5 }, target = 3  
   Output: True

Q23. Write a C# program to skip the first 3 numbers in a list using LINQ.  
   Input: numbers = { 1, 2, 3, 4, 5 }  
   Output: 4, 5

Q24. Write a C# program to find the product of all numbers in a list using LINQ.  
   Input: numbers = { 2, 3, 4 }  
   Output: 24

Q25. Write a C# program to concatenate all strings from a list into a single string using LINQ.  
   Input: words = { "Hello", "World" }  
   Output: HelloWorld

Q26. Write a C# program to sort a list of students by their marks using LINQ.  
   Input: students = { new Student("Alice", 85), new Student("Bob", 90), new Student("Charlie", 80) }  
   Output: Bob, Alice, Charlie

Q27. Write a C# program to find the second largest number in a list using LINQ.  
   Input: numbers = { 1, 2, 3, 4, 5 }  
   Output: 4

Q28. Write a C# program to find the unique elements from two lists using LINQ.  
   Input: list1 = { 1, 2, 3 }, list2 = { 2, 3, 4 }  
   Output: 1, 4

Q29. Write a C# program to convert a list of strings to uppercase using LINQ.  
   Input: words = { "apple", "banana", "grape" }  
   Output: APPLE, BANANA, GRAPE

Q30. Write a C# program to find the intersection of two lists using LINQ.  
   Input: list1 = { 1, 2, 3 }, list2 = { 2, 3, 4 }  
   Output: 2, 3

Q31. Write a C# program to select even-indexed elements from a list using LINQ.  
   Input: numbers = { 10, 20, 30, 40, 50 }  
   Output: 10, 30, 50

Q32. Write a C# program to group a list of strings by the first letter using LINQ.  
   Input: words = { "apple", "banana", "cherry", "apricot" }  
   Output: a: apple, apricot; b: banana; c: cherry

Q33. Write a C# program to find the first word that contains the letter "e" from a list using LINQ.  
   Input: words = { "apple", "banana", "cherry" }  
   Output: apple

Q34. Write a C# program to check if any word in a list starts with a capital letter using LINQ.  
   Input: words = { "apple", "Banana", "cherry" }  
   Output: True

Q35. Write a C# program to get all students who scored above 80 marks using LINQ.  
   Input: students = { new Student("Alice", 85), new Student("Bob", 75), new Student("Charlie", 90) }  
   Output: Alice, Charlie

Q36. Write a C# program to get the average length of strings in a list using LINQ.  
   Input: words = { "apple", "banana", "cherry" }  
   Output: 5.33

Q37. Write a C# program to sort a list of numbers in ascending order using LINQ.  
   Input: numbers = { 5, 2, 9, 1, 6 }  
   Output: 1, 2, 5, 6, 9

Q38. Write a C# program to find all numbers divisible by both 3 and 5 using LINQ.  
   Input: numbers = { 3, 5, 15, 30, 7 }  
   Output: 15, 30

Q39. Write a C# program to find the first word in a list that is longer than 5 characters using LINQ.  
   Input: words = { "apple", "banana", "grape" }  
   Output: banana

Q40. Write a C# program to sum up all the even numbers from a list using LINQ.  
   Input: numbers = { 1, 2, 3, 4, 5 }  
   Output: 6

Q41. Write a C# program to find the frequency of each word in a list using LINQ.  
   Input: words = { "apple", "banana", "apple", "cherry", "banana" }  
   Output: apple: 2, banana: 2, cherry: 1

Q42. Write a C# program to find the words that are longer than 4 characters using LINQ.  
   Input: words = { "apple", "cat", "banana", "dog" }  
   Output: apple, banana

Q43. Write a C# program to find the numbers that are greater than the average in a list using LINQ.  
   Input: numbers = { 5, 10, 15, 20, 25 }  
   Output: 15, 20, 25

Q44. Write a C# program to get the last 3 elements of a list using LINQ.  
   Input: numbers = { 1, 2, 3, 4, 5, 6 }  
   Output: 4, 5, 6

Q45. Write a C# program to remove duplicates from a list of strings using LINQ.  
   Input: words = { "apple", "banana", "apple", "cherry" }  
   Output: apple, banana, cherry

Q46. Write a C# program to find all strings that contain the substring "app" using LINQ.  
   Input: words = { "apple", "banana", "grape", "apricot" }  
   Output: apple, apricot

Q47. Write a C# program to reverse the order of elements in a list using LINQ.  
   Input: numbers = { 1, 2, 3, 4, 5 }  
   Output: 5, 4, 3, 2, 1

Q48. Write a C# program to check if all elements in a list are unique using LINQ.  
   Input: numbers = { 1, 2, 3, 4, 5 }  
   Output: True

Q49. Write a C# program to find the element that appears most frequently in a list using LINQ.  
   Input: numbers = { 1, 2, 2, 3, 3, 3 }  
   Output: 3

Q50. Write a C# program to create a new list of squared values of all even numbers using LINQ.  
   Input: numbers = { 1, 2, 3, 4, 5 }  
   Output: 4, 16

Share on Social Media