C Sharp Logical Test

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

1.

What will be the output of the C#.NET code snippet given below?
byte b1 = 0xF7;
byte b2 = 0xAB;
byte temp;
temp = (byte)(b1 & b2);
Console.Write (temp + " | ");
temp = (byte)(b1^b2);
Console.WriteLine(temp);
Answer:

2.

What will be the output of the C#.NET code snippet given below?
Console.WriteLine(13 / 2 + " | " + 13 % 2);
Answer:

3.

What will be the output of the C#.NET code snippet given below?
int num = 1, z = 5;
if (!(num <= 0))
Console.WriteLine( ++num + z++ + " | " + ++z );
else
Console.WriteLine( --num + z-- + " - " + --z );
Answer:

4.

What will be the output of the C#.NET code snippet given below?
String s1 = " ALL MEN ARE CREATED EQUAL";
String s2;
s2 = s1.Substring(12, 3);
Console.WriteLine(s2);
Answer:

5.

What will be the output of the C#.NET code snippet given below?
String s1 = "Microsoft";
String s2;
s2 = s1.Insert(6, "C#");
Console.WriteLine(s2);
Answer:

6.

What will be the output of the C#.NET code snippet given below?
namespace MfbConsoleApplication

{
class SampleProgram
{
static void Main(string[ ] args)
{
string str= "Hello World!";
Console.WriteLine( String.Compare(str, "Hello World?" ).GetType() );
}
}
}
Console.WriteLine( --num + z-- + " - " + --z );
Answer:

7.

What statements should be added to the subroutine fun( ) if the C#.NET code snippet given
below is to output 9 13?
class BaseClass
{
protected int i = 13;
}
class Derived: BaseClass
{
int i = 9;
public void fun()
{
// [*** Add statement here ***]
}
}
Answer:

8.

What will be the output of the C#.NET code snippet given below?

namespace MfbConsoleApplication
{
class Baseclass
{
public void fun()
{
Console.Write("Base class" + " ");
}
}

// continue to next page


class Derived1: Baseclass
{

new void fun()


{
Console.Write("Derived1 class" + " ");
}
}
class Derived2: Derived1
{
new void fun()
{
Console.Write("Derived2 class" + " ");
}
}
class Program
{
public static void Main(string[ ] args)
{
Derived2 d = new Derived2();
d.fun();
}
}
}

Answer:

9.

What will be the output of the C#.NET code snippet given below?

int[ , , ] a = new int[ 3, 2, 3 ];


Console.WriteLine(a.Length);

Answer:

10. What will be the output of the C#.NET code snippet given below?

int[][] a = new int[2][];


a[0] = new int[4]{6, 1, 4, 3};
a[1] = new int[3]{9, 2, 7};
Console.WriteLine(a[1].GetUpperBound(0));

Answer:

11. What will be the output of the C#.NET code snippet given below?

namespace MfbConsoleApplication
{
class SampleProgram
{
static void Main(string[ ] args)
{
int i, j;
int[ , ] arr = new int[ 2, 2 ];
for(i = 0; i < 2; ++i)
{
for(j = 0; j < 2; ++j)
{
arr[i, j] = i * 17 + i * 17;
Console.Write(arr[ i, j ] + " ");
}
}
}
}
}

Answer:

12. What will be the output of the C#.NET code snippet given below?

namespace MfbConsoleApplication
{
class SampleProgram
{
static void Main(string[] args)
{
int num = 1;
funcv(num);
Console.Write(num + ", ");
funcr(ref num);
Console.Write(num + ", ");
}
static void funcv(int num)
{
num = num + 10; Console.Write(num + ", ");
}
static void funcr (ref int num)
{
num = num + 10; Console.Write(num + ", ");
}
}
}

Answer:

13. What will be the output of the C#.NET code snippet given below?

namespace MfbConsoleApplication
{
class SampleProgram
{
static void Main(string[] args)
{
int a = 5;
int s = 0, c = 0;
Proc(a, ref s, ref c);
Console.WriteLine(s + " " + c);
}
static void Proc(int x, ref int ss, ref int cc)
{
ss = x * x;
cc = x * x * x;
}
}
}

Answer:

14. What will be the output of the C#.NET code snippet given below?

namespace MfbConsoleApplication
{
class SampleProgram
{
static void Main(string[ ] args)
{
int i;
int res = fun(out i);
Console.WriteLine(res);
}
static int fun (out int i)
{
int s = 1;
i = 7;
for(int j = 1; j <= i; j++)
{
s = s * j;
}
return s;
}
}
}

Answer:

15. What will be the output of the C#.NET code snippet given below?

int i;
for(i = 0; i<=10; i++)
{
if(i == 4)
{
Console.Write(i + " "); continue;
}
else if (i != 4)
Console.Write(i + " "); else
break;
}
Answer:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy