0
0
C Sharp (C#)programming~20 mins

Immediate execution methods in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Immediate Execution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Count() on a filtered list
What is the output of this C# code using LINQ's immediate execution method Count()?
C Sharp (C#)
using System;
using System.Linq;

class Program {
    static void Main() {
        int[] numbers = {1, 2, 3, 4, 5};
        int count = numbers.Where(n => n > 3).Count();
        Console.WriteLine(count);
    }
}
A0
B2
C3
D5
Attempts:
2 left
💡 Hint
Count() returns how many items match the condition immediately.
Predict Output
intermediate
2:00remaining
Result of ToList() on a query
What will be printed by this C# program using ToList() for immediate execution?
C Sharp (C#)
using System;
using System.Linq;
using System.Collections.Generic;

class Program {
    static void Main() {
        var words = new List<string> {"apple", "banana", "cherry"};
        var filtered = words.Where(w => w.Contains('a')).ToList();
        Console.WriteLine(filtered.Count);
    }
}
A2
B3
C1
D0
Attempts:
2 left
💡 Hint
ToList() creates a list immediately with all matching items.
Predict Output
advanced
2:00remaining
Output of First() with condition
What does this C# code print when using First() as an immediate execution method?
C Sharp (C#)
using System;
using System.Linq;

class Program {
    static void Main() {
        int[] nums = {10, 20, 30, 40};
        int first = nums.Where(n => n > 15).First();
        Console.WriteLine(first);
    }
}
A20
B10
C30
DThrows InvalidOperationException
Attempts:
2 left
💡 Hint
First() returns the first element that matches the condition immediately.
Predict Output
advanced
2:00remaining
Output of Single() with one matching element
What will this C# program print using Single() as an immediate execution method?
C Sharp (C#)
using System;
using System.Linq;

class Program {
    static void Main() {
        int[] values = {5, 10, 15};
        int single = values.Single(v => v == 10);
        Console.WriteLine(single);
    }
}
A15
B5
CThrows InvalidOperationException
D10
Attempts:
2 left
💡 Hint
Single() returns the only element matching the condition or throws if none or multiple.
Predict Output
expert
2:00remaining
Output of Count() after modifying source collection
What is the output of this C# program that uses Count() immediate execution after modifying the source array?
C Sharp (C#)
using System;
using System.Linq;

class Program {
    static void Main() {
        int[] data = {1, 2, 3, 4};
        var query = data.Where(x => x > 2);
        data[2] = 10; // change 3 to 10
        int count = query.Count();
        Console.WriteLine(count);
    }
}
A3
B1
C2
D0
Attempts:
2 left
💡 Hint
Count() evaluates the query immediately using the current state of the data.