Q.1 What would be the output of the following program? using System; namespaceifta classdatatypes static void Main(string[] args) inti; Console.WriteLine("i is not used inthis program!"); A. i is not used in this program! B. Compilation Error C. No output D. None of the Above ANSWER : Option A i is not used in this program! If a variable is not initialized but is not used anywhere, there is no issue and the program executes perfectly fine. The error comes only when we try to access the value of an uninitialized variable. Q.2 Correct output for code is? static void Main(string[] args) float a = 10.553f; long b = 12L; int c; c = Convert.ToInt32(a + b); Console.WriteLine(c); A. 23.453 B. 22 C. 23 D. 22.453 ANSWER : Option C 23 The two datatype ^aeur~float^aeurtm and ^aeur~long^aeurtm after arithmetic operation completely converted to nearest whole number 23. Page 1
Q.3 Which of the following statement is true about data types in C#? I. Size of byte and sbyte is same. II. Size of short and ushort is same. III. Size of int and uint is same. IV. Size of long and ulong is same. V. Size of double and Decimal is same. A. I, V. B. II, V C. III, IV, V D. I, II, III, IV ANSWER : Option D I, II, III, IV Size of byte and sbyte : 1 byte Size of short and ushort: 2 bytes Size of int and uint: 4 bytes Size of long and long: 8 bytes Size of double: 8 bytes Size of Decimal: 16 bytes Q.4 Which of the following statement correctly assigns a value 33 to a variable c? byte a = 11, b = 22, c; A. c = (byte) (a + b); B. c = (byte) a + (byte) b; C. c = (int) a + (int) b; D. c = (int)(a + b); ANSWER : Option A c = (byte) (a + b); Because the arithmetic expression on the right-hand side of the assignment operator evaluates to int by default. For short and byte types compiler asks for explicit conversion. Q.5 Which of the following lines perform Automatic Type Conversion? (Choose all that apply) using System; namespaceifta classautoconvertion static void Main(string[] args) byte b=10; //line8 Page 2
short s=20; //line9 inti; i=b; //line11 Console.WriteLine("i=" +i); i=s; //line13 Console.WriteLine("i=" +i); A. Line8 B. Line9 C. Line11 D. Line13 ANSWER : Option a, b, c, d Line8 Line9 Line11 Line13 C# performs an automatic type conversion when storing a literal integer constant into variables of type byte, short, long and char.thus, All the options are correct.in the line8 and line9 the integer constant 10 and 20 are assigned to byte and short respectively. Here Automatic Type Conversion occurs. In the line11 and line13 "Widening" happens i.e. byte and short are widened/ typecast into a larger datatype i.e. int. Q.6 Which of the given stream method provides the access to the input console in C#.NET? A. Console.Out B. Console.Error C. Console.In D. All of the mentioned ANSWER : Option C Console.In Console.In is an instance of TextReader, and we can use the methods and properties defined by TextReader to access it to read the input from the keyboard. Q.7 Which of the given stream method provides the access to the output console by default in C#.NET? A. Console.In B. Console.Out Page 3
C. Console.Error D. All of the mentioned ANSWER : Option B Console.Out The standard output stream Console.Out sends output to the screen by default. Q.8 Which of the following statements are correct about datatypes in C#.NET? I. Every datatype is either a value type or a reference type. II. Value types are always created on the heap. III. Reference types are always created on the stack. IV. Mapping of every value type to a type in Common Type System facilitates Interoperability in C#.NET. V. Every reference type gets mapped to a type in Common Type System. A. 1, 3 B. 2, 5 C. 1, 4 D. 3, 4 ANSWER : Option C 1, 4 DataType is either a value type or a reference type, other than that no other type is available. Value types are always created on the Stack.Reference types are always created on the Heap. Mapping of every value type to a type in Common Type System facilitates Interoperability in C#. NET so that MSIL be prepared that is same for all language. Q.9 What would be the output of the following program? using System; namespaceifta classdatatypes static void Main(string[] args) byte b; short s; inti; long l; float f; double d; Page 4
boolbl; char c; Console.WriteLine("byte="+b+" short="+s+" int="+i); Console.WriteLine("long="+l+" float="+f+" double="+d); Console.WriteLine("char="+c+" bool="+bl); A. byte=0 short=0 int=0 long=0 float=0 double=0 char= bool=false B. byte=0 short=0 int=0 long=0 float=0.000000 double=0.000000 char= bool=false C. Compilation Error D. None of the Above ANSWER : Option C Compilation Error We get the following Error: Description: Use of unassigned local variable In C#, Every local variable has to be initialized before it can be used. Q.10 Which of the following statements are TRUE about the.net CLR? It provides a language-neutral development & execution environment. It ensures that an application would not be able to access memory that it is not authorized to access. It provides services to run "managed" applications. The resources are garbage collected. It provides services to run "unmanaged" applications. A. Only 1 and 2 B. Only 1, 2 and 4 C. 1, 2, 3, 4 D. Only 4 and 5 ANSWER : Option C 1, 2, 3, 4 CLR (Common Language Runtime) is a heart of Dot Net Framework. It is a core runtime environment of.net Framework for executing applications. The main function of Common Language Runtime (CLR) is to convert the Managed Code into native code and then execute the Program. It acts as a layer between Operating Systems and the applications written in.net languages. CLR handles the execution of code and provides useful services for the implementation of the program. In addition to executing code, CLR provides services such as memory management, thread management, security management, code verification, compilation, Page 5
and other system services Q.11 Which of the following is the correct ways to set a value 3.14 in a variable pi such that it cannot be modified? A. float pi = 3.14F; B. #define pi 3.14F; C. const float pi = 3.14F; D. const float pi; pi = 3.14F; ANSWER : Option C const float pi = 3.14F; Const keyword is used for declaring a Constant variable, where Constant variable must be declare at the time of declaration only. Syntax for declaring Constant is : [const]< type><var><=value> Q.12 Arrange following datatype in order of increasing magnitude sbyte, short, long, int. A. long< short <int<sbyte B. sbyte< short <int< long C. short<sbyte<int< long D. short<int<sbyte< long ANSWER : Option B sbyte< short <int< long Holds signed 8-bit (1-byte) integers that range in value from -128 through 127. Use the SByte data type to contain integer values that do not require the full data width of Integer or even the half data width of Short. In some cases the common language runtime might be able to pack your SByte variables closely together and save memory consumption. The default value of SByte is 0. Holds signed 16-bit (2-byte) integers that range in value from -32,768 through 32,767. Use the Short data type to contain integer values that do not require the full data width of Integer. In some cases, the common language runtime can pack your Shortvariables closely together and save memory consumption.the default value of Short is 0. Holds signed 32-bit (4-byte) integers that range in value from -2,147,483,648 through 2,147,483,647. The Integer data type provides optimal performance on a 32-bit processor. The other integral types are slower to load and store from and to memory. The default value of Integer is 0. Holds signed 64-bit (8-byte) integers ranging in value from -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807 (9.2...E+18). Use the Long data type to contain integer numbers that are too large to fit in the Page 6
Integer data type.the default value of Long is 0. Q.13 Missing deceleration type of ^aeur~b^aeurtm. Static Void Main(String[] args) constint m = 100; int n = 10; constint k = n / 5 * 100 * n ; Console.WriteLine(m * k); Console.ReadLine(); A. ^aeur~k^aeurtm should not be declared constant B. Expression assigned to ^aeur~k^aeurtm should be constant in nature C. Expression (m * k) is invalid D. ^aeur~m ^aeur~ is declared in invalid format ANSWER : Option B Expression assigned to ^aeur~k^aeurtm should be constant in nature ^aeurtmk^aeurtm should be declared as constint k = 10/5 * 100*10 i.e only constant values should be assigned to a constant. Q.14 Default Type of number without decimal is? A. Long Int B. Unsigned Long C. Int D. Unsigned Int ANSWER : Option C Unsigned Int a decimal and an int are mixed in the same expression. The result evaluates to the decimal type. Q.15 The number of input methods defined by the stream method Console.In in C#.NET is? A. 4 B. 3 C. 2 D. 1 ANSWER : Option B 3 Two basic methods : read() and readline() and third method readkey() introduced in.net FrameWork 2.0. Page 7
Q.16 Which of the class provides the operation of reading from and writing to the console in C#.NET? A. System.Array B. System.Output C. System.ReadLine D. System.Console ANSWER : Option D System.Console The method for reading and writing to the console in C#.NET is provided by System.Console class. This class gives us access to the standard input,output and standard error streams. Q.17 Which of the following is the correct default value of a Boolean type? A. 0 B. 1 C. True D. False ANSWER : Option D False Boolean types return only true and false but default value of boolean type will be false. Q.18 Correct Declaration of Values to variables ^aeur~a^aeurtm and ^aeur~b^aeurtm? A. int a = 32, b = 40.6; B. int a = 42; b = 40; C. int a = 32; int b = 40; D. int a = b = 42; ANSWER : Option C int a = 32; int b = 40; a) Although,deceleration of ^aeur~b^aeurtm and ^aeur~a^aeurtm are correct but initialization of value to ^aeur~b^aeurtm should be ^aeur~int^aeurtm datatype not float. b) Missing deceleration type of ^aeur~b^aeurtm. c) correctly declared datatypes ^aeur~a^aeurtm and ^aeur~b^aeurtm. d) ^aeur~b^aeurtm can^aeurtmt be assigned values before declaration. Missing deceleration type of ^aeur~b^aeurtm. Page 8
Q.19 Which of the following statements are correct? I. We can assign values of any type to variables of type object. II. When a variable of a value type is converted to object, it is said to be unboxed. III. When a variable of type object is converted to a value type, it is said to be boxed. IV. Boolean variable cannot have a value of null. V. When a value type is boxed, an entirely new object must be allocated and constructed. A. 2,5 B. 1,5 C. 3, 4 D. 2, 3 ANSWER : Option B 1,5 We can assign the any type value to the variable of object data type. Boxing means suppose you have declared a variable as simple data type and we can change it into reference type. After task complete if we want to change the reference type into simple data type it is called unboxing. Q.20 Select the correct methods provided by Console.In? A. Read(), ReadLine() B. ReadKey(), ReadLine() C. Read(), ReadLine(), ReadKey() D. ReadKey(), ReadLine() ANSWER : Option C Read(), ReadLine(), ReadKey() The two method Read() and ReadLine() available in.net Framework 1.0 and Third method ReadKey() was added by.net Framework 2.0. Q.21 Which Conversion function of ^aeur~convert.toint32()^aeurtm and ^aeur~int32.parse()^aeurtm is efficient? I. Int32.Parse() only used for strings and throws arguement exception for null string II.Convert.Int32() used for datatypes and returns directly ^aeurtm0? for null string. A. 2 B. Both 1,2 C. 1 D. None of the mentioned ANSWER : Option A 2 Page 9
Convenient for every datatype so mostly preferred. Q.22 What would be the output of the following program? using System; namespaceifta class DataTypesScope3 static void Main(string[] args) for (inti=1;i<=3 ;i++ ) int y=1; Console.WriteLine("i="+i+" y="+y); y++; A. i=1 y=1i=2 y=2i=3 y=3 B. i=1 y=1i=2 y=1i=3 y=1 C. i=1 y=1i=1 y=1i=1 y=1 D. Compilation Error ANSWER : Option B i=1 y=1i=2 y=1i=3 y=1 The declaration of variable y is inside the for loop and is executed every time the control enters the loop thus, re-initializing it to 1 every time.so, Y remains 1 across all the 3 iterations. A variable declared inside a block is lost every time the control goes out of the scope thus the y declared here is created afresh and discarded at the end of every iteration. Q.23 Which datatype should be more preferred for storing a simple number like 35 to improve execution speed of a program? A. sbyte B. short C. int D. long ANSWER : Option A sbyte Wider datatype like int,long takes more Page 10
time for manipulation of a program. Q.24 Choose the output return when read() reads the character from the console? A. String B. Char C. Integer D. Boolean ANSWER : Option C Integer Read() returns the character read from the console. It returns the result. The character is returned as an int, which should be cast to char. Q.25 Choose ".NET class" name from which datatype ^aeuroeuint^aeur Page 11