51. What will be the output of the following C# code snippet?
class Program
{
static void Main(string[] args)
{
string[] strs = { ".com", ".net", "facebook.com", "google.net",
"test", "netflix.net", "hsNameD.com" };
var netAddrs = from addr in strs
where addr.Length > 4 && addr.EndsWith(".net",
StringComparison.Ordinal)
select addr;
foreach (var str in netAddrs) Console.WriteLine(str);
Console.ReadLine();
}
}
class Program
{
static void Main(string[] args)
{
string[] strs = { ".com", ".net", "facebook.com", "google.net",
"test", "netflix.net", "hsNameD.com" };
var netAddrs = from addr in strs
where addr.Length > 4 && addr.EndsWith(".net",
StringComparison.Ordinal)
select addr;
foreach (var str in netAddrs) Console.WriteLine(str);
Console.ReadLine();
}
}
52. What will be the output of the following C# code snippet?
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
var posNums = nums.Where(n => n > 0).Select(r => r*2).
OrderByDescending(r=>r);
Console.Write("The positive values in nums: ");
foreach(int i in posNums)
Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
var posNums = nums.Where(n => n > 0).Select(r => r*2).
OrderByDescending(r=>r);
Console.Write("The positive values in nums: ");
foreach(int i in posNums)
Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}
53. What will be the output of the following C# code snippet?
class UseTypeof
{
static void Main()
{
Type t = typeof(StreamReader);
Console.WriteLine(t.FullName);
if(t.IsClass) Console.WriteLine("Is a class.");
if(t.IsAbstract) Console.WriteLine("Is abstract.");
else Console.WriteLine("Is concrete.");
}
}
class UseTypeof
{
static void Main()
{
Type t = typeof(StreamReader);
Console.WriteLine(t.FullName);
if(t.IsClass) Console.WriteLine("Is a class.");
if(t.IsAbstract) Console.WriteLine("Is abstract.");
else Console.WriteLine("Is concrete.");
}
}
54. What will be the output of the following C# code snippet?
static void Main(string[] args)
{
int[] nums = { 5, 4, 6, 3, 14, 9, 8, 17, 1, 24, -1, 0 };
Array.Sort(nums);
int idx = Array.BinarySearch(nums, 14);
if (idx == 9)
{
Console.WriteLine(Convert.ToBoolean(1));
}
else
{
Console.WriteLine(Convert.ToBoolean(0));
}
Console.WriteLine("Index of 14 is " + idx);
Console.ReadLine();
}
static void Main(string[] args)
{
int[] nums = { 5, 4, 6, 3, 14, 9, 8, 17, 1, 24, -1, 0 };
Array.Sort(nums);
int idx = Array.BinarySearch(nums, 14);
if (idx == 9)
{
Console.WriteLine(Convert.ToBoolean(1));
}
else
{
Console.WriteLine(Convert.ToBoolean(0));
}
Console.WriteLine("Index of 14 is " + idx);
Console.ReadLine();
}
55. Choose the namespace in which Expression trees are encapsulated?
56. Which mechanism among the following helps in identifying a type during the execution of a program?
57. In the following C# code, which query will work according to the set of code?
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
int len = /*_________________ */
Console.WriteLine("The number of positive values in nums: " + len);
Console.ReadLine();
}
}
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, -2, 3, 0, -4, 5 };
int len = /*_________________ */
Console.WriteLine("The number of positive values in nums: " + len);
Console.ReadLine();
}
}
58. Choose the correct statement about the IComparer interface in C#?
59. What will be the output of the following C# code snippet?
class Program
{
static void Main(string[] args)
{
int[] nums = {1};
var posNums = from n in nums
wheres n > 0
select Math.Max(78, 9);
Console.Write("The largest values in nums: ");
foreach (int i in posNums) Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}
class Program
{
static void Main(string[] args)
{
int[] nums = {1};
var posNums = from n in nums
wheres n > 0
select Math.Max(78, 9);
Console.Write("The largest values in nums: ");
foreach (int i in posNums) Console.Write(i + " ");
Console.WriteLine();
Console.ReadLine();
}
}
60. What does the following property defined in the array class defines in C#?
public bool IsReadOnly { get; }
public bool IsReadOnly { get; }