Select an option to see the answer and solution.
LINQ (Language
practice.
Practice every MCQ with options. Use Show answers when you want the correct option and solution.
85
Questions
4/5
Page
Pick an option on a question to see the right answer and solution.
Select an option to see the answer and solution.
static void Main()
{
int[] nums = { 1, 2, 3, 4, 5 };
Console.Write("Original order: ");
foreach(int i in nums)
Console.Write(i + " ");
Array.Reverse(nums);
Console.Write("Reversed order: ");
foreach(int i in nums)
Console.Write(i + " ");
Console.WriteLine();
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5};
var posNums = from n in nums
where n >= 0
select n;
foreach (int i in posNums)
Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
var posNums = from n in nums
where n > -5 && n < 6
orderby n descending
select n;
Console.Write("The positive values in nums: ");
foreach (int i in posNums) Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
var posNums = from n in nums
where n % 2 ==0
select n;
Console.Write("The positive values in nums: ");
foreach (int i in posNums) Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}Select an option to see the answer and solution.
class Program
{
static void Main(string[] args)
{
int[] nums = { 16, 9, 25};
var posNums = from n in nums
where n > 0
select Math.Sqrt(n);
Console.Write("The positive values in nums: ");
foreach (int i in posNums) Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, -3, 5 };
var posNums = from n in nums
orderby n descending
select n*4 / 2;
Console.Write("The values in nums: ");
foreach (int i in posNums) Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}Select an option to see the answer and solution.
class A {}
class B : A {}
class CheckCast
{
static void Main()
{
A a = new A();
B b = new B();
b = a as B;
b = null;
if(b==null)
Console.WriteLine("The cast in b = (B) a is NOT allowed.");
else
Console.WriteLine("The cast in b = (B) a is allowed");
}
}Select an option to see the answer and solution.
Select an option to see the answer and solution.
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
var posNums = from n in nums
where n > 0
select n;
int len = posNums.Count();
Console.WriteLine(len);
Console.ReadLine();
}
}Select an option to see the answer and solution.
static void Main(string[] args)
{
string[] strings = {"beta", "alpha", "gamma"};
Console.WriteLine("Array elements: ");
DisplayArray(strings);
Array.Reverse(strings);
Console.WriteLine("Array elements now: ");
DisplayArray(strings);
Console.ReadLine();
}
public static void DisplayArray(Array array)
{
foreach (object o in array)
{
Console.Write("{0} ", o);
}
Console.WriteLine();
}Select an option to see the answer and solution.
expr is typeSelect an option to see the answer and solution.
Select an option to see the answer and solution.
public static int BinarySearch<T>(T[] array, int index, int length, T value)Select an option to see the answer and solution.
class Program
{
static void Main(string[] args)
{
Expression<Func<int, int, bool>>
IsFactorExp = (n, d) => (d != 0) ? (n % d) == 0 : false;
Func<int, int, bool> IsFactor = IsFactorExp.Compile();
if (IsFactor(10, 5))
Console.WriteLine("5 is a factor of 10.");
if (!IsFactor(343, 7))
Console.WriteLine("7 is not a factor of 10.");
Console.ReadLine();
}
}Select an option to see the answer and solution.