C# Test 1

What will be the output of the 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;
}

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);

Which of the following statements are correct about the C#.NET program given below?

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

1. An error will be reported in the statement s, c = fun(a); since multiple values returned from a function cannot be collected in this manner.
2. It will output 25 125.
3.It will output 25 0.
4. It will output 0 125.
5. An error will be reported in the statement return ss, cc; since a function cannot return multiple values.

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

namespace IndiabixConsoleApplication
{
class SampleProgram
{
static void Main(string[ ] args)
{
int i = 5;
int j;
fun1(ref i);
fun2(out j);
Console.WriteLine(i + ", " + j);
}
static void funl(ref int x)
{
x = x * x;
}
static void fun2(out int x)
{
x = 6;
x = x * x;
}
}
}

The this reference gets created when a member function (non-shared) of a class is called.

Which of the following statements is correct about the C#.NET code snippet given below?

int i;
int j = new int();
i = 10;
j = 20;
String str;
str = i.ToString();
str = j.ToString();

Which of the following statements are correct about the C#.NET code snippet given below?

namespace IndiabixConsoleApplication
{
class Sample
{
int i, j;
public void SetData(int ii, int jj)
{
this.i = ii;
this.j = jj
}
}
class MyProgram
{
static void Main(string[ ] args)
{
Sample s1 = new Sample();
s1.SetData(10, 2);
Sample s2 = new Sample();
s2.SetData(5, 10);
}
}
}

Which of the following can be facilitated by the Inheritance mechanism?
1. Use the existing functionality of base class.
2. Overrride the existing functionality of base class.
3. Implement new functionality in the derived class.
4. Implement polymorphic behaviour.
5. Implement containership.


Which of the following should be used to implement a 'Like a' or a 'Kind of' relationship between two entities?

Which of the following statements are correct about the C#.NET code snippet given below?

int[][]intMyArr = new int[2][]; 
intMyArr[0] = new int[4]{6, 1, 4, 3};
intMyArr[1] = new int[3]{9, 2, 7};

Which of the following statements will correctly copy the contents of one string into another ?

Which of the following statements about a String is correct?

Which of the following will be the correct output for the program given below?

namespace IndiabixConsoleApplication
{
struct Sample
{
public int i;
}
class MyProgram
{
static void Main(string[] args)
{
Sample x = new Sample();
Sample y;
x.i = 9;
y = x;
y.i = 5;
Console.WriteLine(x.i + " " + y.i);
}
}
}

Which of the following are correct ways to pass a parameter to an attribute?
1. By value
2. By reference
3. By address
4. By position
5. By name

Which of the following statements are correct about inspecting an attribute in C#.NET?
1. An attribute can be inspected at link-time.
2. An attribute can be inspected at compile-time.
3. An attribute can be inspected at run-time.
4. An attribute can be inspected at design-time.

Which of the following statements are correct about the C#.NET code snippet given below?

Stack st = new Stack();
st.Push("hello");
st.Push(8.2);
st.Push(5);
st.Push('b');
st.Push(true);

Which of the following is the Object Oriented way of handling run-time errors?

Exceptions can be thrown even from a constructor, whereas error codes cannot be returned from a constructor.

Which of the following statements is correct about the C#.NET program given below if a value "ABCD" is input to it?

using System;
namespace IndiabixConsoleApplication
{
class MyProgram
{
static void Main(string[] args)
{
int index;
int val = 55;
int[] a = new int[5];
try
{
Console.Write("Enter a number: ");
index = Convert.ToInt32(Console.ReadLine());
a[index] = val;
}
catch(FormatException e)
{
Console.Write("Bad Format ");
}
catch(IndexOutOfRangeException e)
{
Console.Write("Index out of bounds ");
}
Console.Write("Remaining program ");
}
}
}

Which of the following statements is correct about an interface?

Schreibe einen Kommentar