Framework in .NET - placement questions

Framework in .NET - placement questions


Q.1 Structure/struct comes under which type?

A) Value type
B) Reference type
C) Derived type
D) None of the above.

View Answer / Hide Answer

ANSWER: A




Q.2 Which of the following are value types?

A. Decimal
B. Integer
C. System.Drawing.Point
D. All of the above.

View Answer / Hide Answer

ANSWER: D




Q.3 Which is the correct declaration for a nullable integer?

A) int i = null;
B) Nullable(int) i = null;
C) Nullable<int> i = null;
D) None of the above.

View Answer / Hide Answer

ANSWER: C

Explanation:
You can declare the variable as nullable if you want to determine whether a value has not been assigned. You could also use the following syntax to declare integer nullable type: int? i = null; A Nullable<bool> can be assigned the values true false, or null.




Q.4 The default type of enumeration elements is int. Choose the correct given below code to declare an enum as byte .

A) Days : byte {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};
B) enum Days : byte {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};
C) Days : byte enum{Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};
D) None of the above.

View Answer / Hide Answer

ANSWER: B




Q.5 Reference types stores actual data in which memory location?

A) Heap
B) Stack
C) Secondry Storage
D) None of the above.

View Answer / Hide Answer

ANSWER: A

Explanation:
Reference types store the address of their data on the stack and the actual data is stored in an area of memory called the heap.
class RefDemo
{
public int x;
}
class MyProgram
{
static void Main(string[] args)
{
RefDemo obj1 = new RefDemo();
RefDemo obj2 = obj1;
obj1.x = 10;
obj2.x = 20;
Console.WriteLine("obj1.x = {0} , obj2.x = {1}", obj1.x, obj2.x);
}
}




Q.6 Trace the output of given below code.

using System;
struct Numbers
{
public int val;
public Numbers(int n)
{
val = n;
}

}

class MyProgram
{
static void Main(string[] args)
{
Numbers n1 = new Numbers(0);
Numbers n2 = n1;
n1.val += 1;
n2.val += 2;
Console.WriteLine("n1 = {0}, n2 = {1}", n1.val, n2.val);
}
}

A) n1=1 , n2=2
B) n1=1 , n2=3
C) n1=2 , n2=2
D) None of the above.

View Answer / Hide Answer

ANSWER: A




Q.7 Trace the output of given below code.

using System;
class Numbers
{
public int val;
public Numbers(int n)
{
val = n;
}
}
class MyProgram
{
static void Main(string[] args)
{
Numbers n1 = new Numbers (0);
Numbers n2 = n1;
n1.val += 1;
n2.val += 2;
Console.WriteLine("n1 = {0}, n2 = {1}", n1.val, n2.val);
}
}

A) n1 = 3, n2 = 3
B) n1 = 3, n2 = 3
C) n1 = 3, n2 = 3
D) n1 = 3, n2 = 3

View Answer / Hide Answer

ANSWER: B




Q.8 With strict conversions enabled, which of the following would allow an implicit conversion?

A. Int16 to Int32
B. Int32 to Int16
C. Int16 to Double
D. Option A and C are correct.

View Answer / Hide Answer

ANSWER: D




Q.9 According to given below statements, choose the correct option regarding boxing and unboxing.

Statement 1: Boxing converts a value type to a reference type.
Statement 2: Unboxing converts a reference type to a value type.
Statement 3: Unboxing converts a value type to a reference type.
Statement 4: Boxing converts a reference type to a value type.

A) Statement 1 and 2 are correct.
B) Statement 3 and 4 are correct.
C) Statement 1 and 3 are correct.
D) Statement 2 and 4 are correct.

View Answer / Hide Answer

ANSWER: A

Explanation:
Converting a value type to reference type is called Boxing.
int i = 12;
object o = (object) i;
Converting a reference type to value type is called Boxing.
object o = 12;
int i = (int) o;




Q.10 According to given below statements, choose the correct option regarding boxing and unboxing.

Statement 1: Strings of type System.String is immutable in .NET
Statement 2: Strings of type System.String is mutable in .NET
Statement 3: StringBuilder class is used to create mutable strings.
Statement 4: StringBuilder class is used to create immutable strings.

A) Statement 1 and 2 are correct.
B) Statement 3 and 4 are correct.
C) Statement 1 and 3 are correct.
D) Statement 2 and 4 are correct.

View Answer / Hide Answer

ANSWER: C

Explanation:

Strings of type System.String are immutable in .NET. That means, if you have done any change to a string, new string will be created and abandon the old one.
string s;
s = "Hello"; // “Hello"
s += " how"; // "Hello how "
s += " are"; // "Hello how are "
s += "you"; // "Hello how are you"
Console.WriteLine(s);

Only the last string has a reference; the remaining will be disposed of during garbage collection. If you want to avoid these types of temporary strings use StringBuilder class. This class is available in System.Text namespace.

System.Text.StringBuilder sb = new System.Text.StringBuilder(30);
sb.Append("Hello");
sb.Append(" how");
sb.Append(" are");
sb.Append(" you");
string s = sb.ToString(); // Copy result to string.
Console.WriteLine(s);




Q.11 Which of the following statements are correct about an enum used in C#.NET?

A) An enumerator contains white space in its name.
B) An enumerator cannot contain white space in its name.
C) The value of each successive enumerator is decreased by 1.
D) None of the above.

View Answer / Hide Answer

ANSWER: B




Q.12 Trace the correct output for the following given below C#.NET code snippet

using System;
enum Days : int
{
sun = -5,
mon,
tue
}
class MyProgram
{
static void Main(string[] args)
{
Console.Write( (int) Days.sun + ", ");
Console.Write( (int) Days.mon + ", ");
Console.Write( (int) Days.tue );
Console.WriteLine();
}
}

A) You cannot assign negative value to the enum variable.
B) -5, -4, -3
C) Compile time error
D) -5, -6, -7

View Answer / Hide Answer

ANSWER: B




Q.13 C#.Net Primitive Type float mapped with which FCL type?

A) System.Triple
B) System.Double
C) System.Single
D) None of the above.

View Answer / Hide Answer

ANSWER: C




Q.14 What is the default access modifier for a class in c#.Net?

A) internal
B) private
C) public
D) protected

View Answer / Hide Answer

ANSWER: A

Explanation:

By default the access modifier for a class in c#.Net is internal in a namespace. You can also declare the class as public. You cannot explicitly declare a class in a namespace as private, protected, or protected internal.
If the class is nested within another class default access specifier is private.




Q.15 Within a namespace, what type you can declare?

A) Another namespace, class, interface, struct, enum, delegate
B) Only class and interface.
C) only class
D) None of the above.

View Answer / Hide Answer

ANSWER: A

Explnation:

Within a namespace, you can declare one or more of the following types:
Another namespace, class, interface, struct, enum, delegate.

using System;
namespace DemoNamespace
{
class DemoClass { }
interface DemoInterface { }
struct DemoStruct { }
enum DemoeEnum { a, b }
delegate void SampleDelegateDemo(int i);
namespace SampleNamespace.Nested
{
class SampleClass
{
static void Main()
{
Console.WriteLine("Welcome at careerRide.com");
}
}
}

}


Post your comment