72. What will be the output of the following C# code snippet?
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();
}
}
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();
}
}
73. What will be the output of the following C# code snippet?
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");
}
}
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");
}
}
74. Select the statement which are correct about RTTI(Runtime type identification)?
75. In the following C# code, what does the output represent?
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();
}
}
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();
}
}
76. What will be the output of the following C# code snippet?
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();
}
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();
}
77. What does the following C# code signify?
expr is type
expr is type
78. Which operator among the following is used to perform the operation of boxing, unboxing, reference and identity conversions?
79. What does the following property define in C#?
public static int BinarySearch<T>(T[] array, int index, int length, T value)
public static int BinarySearch<T>(T[] array, int index, int length, T value)
80. What will be the output of the following C# code snippet?
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();
}
}
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();
}
}