Monday, February 28, 2011

MCQ: C#


You are designing a Windows Form that enables you to add a new product to the product catalog of your company. You need to validate the controls as the user enters the data. If incorrect data is entered in the field, you should set the focus back to the control and ask the user to enter the correct data. Which of the following events will you use to validate user input?
A. LostFocus
B. Validating
C. Leave
D. Validated
ANSWER: B

You have an order entry form. When an exception occurs, you want to get information about the sequence of method calls and the line number in the method where the exception occurs. Which property of your custom exception class that derives from the ApplicationException class should be used?
A. HelpLink
B. InnerException
C. Message
D. StackTrace
ANSWER: D

What are the types of assemblies possible?
A. Private
B. Public/Shared
C. Satellite assembly
D. All
ANSWER: D

Which of the following is responsible for verifying  that a code written in c# is type safe or not?
A. Language Compiler
B. JIT Compiler
C. CLR
D. Interpreter
ANSWER: B

Boxing is computationally  more expensive process than unboxing:
A. True
B. False
ANSWER:A

Function pointer ensures type safety:
A. True
B. False
ANSWER: B

How should you arrange catch blocks?
A. Only one catch block for each try block.
B. Several catch blocks for a try block, arranged in order starting with Exception and ending with the most specific exception.
C. Several catch blocks within one try block, arranged starting with the most specific exception and ending with Exception.
D. The catch blocks should be used only when a finally block is not used.
ANSWER : C

You have designed a logon form with two TextBox controls named txtUserName and txtpassword. You want to ensure that the user can enter only lowercase characters in the controls. Which of the following solutions will fulfill this requirement using the simplest method?
A. Program the KeyPress event of the TextBox controls to convert uppercase letters to lowercase letters.
B. Create a single event handler that is attached to the KeyPress event of the form. Program this event handler to convert the uppercase letters to lowercase ones.
C. Set the CharacterCasing property of the Textbox controls to Lower.
D. Use the CharacterCasing method of the controls to convert the letters to lowercase letters.
ANSWER : C

You are creating an order-tracking application using a Visual C# .NET Windows application. When you are unable to track a particular order number entered by the user, you need to raise an exception. Which of the following options will help you to raise an exception?
A. try block
B. catch block
C. finally block
D. throw statement
ANSWER : D

Which of the following events will fire when the Insert key is pressed?
A. KeyDown
B. KeyPress
C. KeyUp
D. KeyDown,KeyPress
ANSWER : D

What is the Maximum and Minimum Size of the Int64?
A. 9,223,372,036,854,775,808 / 9,223,372,036,854,775,808
B. 9,223,372,036,854,771,024 / 9,223,372,036,854,771,024
C. 6,400,000,000,000,000,000 / 6,400,000,000,000,000,000
ANSWER: A

What is Minimum and Maximum Size of Int32 ?
A. -3,200,102,400 / 3,200,102,448
B. -2,147,483,648 / 2,147,483,648 
C. -3,200,000,000 / 3,200,000,000
ANSWER: B

What is minimum and Maximum Size of Int16 ?
A. -32,256 / 32,256
B. -16,768 / 16,768
C. -32,768 / 32,768 
D. -16,256 / 16,256
ANSWER: C

5. What is the use of Partial Class ?
A. Reduction in file contention in shared development environments. The forms designer and the developer are not both trying to change the same file
B. Isolation of low-level details. You don't have to worry about the details of how the individual controls are instantiated and initialized
C. Protection for generated code through changes. You are less likely to change the generated code, and any code that you add will not be in the designer file and is protected.
D. All the above 
ANSWER: D

How many constructors does a class have?
A. One
B. Two
C. Three
D. Many  
ANSWER: D

Is XML case-sensitive?
A. Yes 
B. No
C. None of the above
ANSWER: A

Can you change the value of a variable while debugging a C# application?
A. Yes 
B. No
C. None of the above
ANSWER: A

Can multiple catch blocks be executed?
A. Yes
B. No
C. None of the above
ANSWER: B

Does Abstract classes have constructor?
A. No
B. Yes 
C. Not possible
ANSWER: A

What is the base class for the system element hierarchy ?
A. CIM_LogicalElement
B. CIM_ManagedSystemElement 
C. Win32_Process
D. Win32_NetworkAdapter
ANSWER: B

What are valid signatures for the Main function?
A. public static void Main()
B. public static int Main()
C. public static void Main( string[] args )
D. Above ALL  
ANSWER: D

What is The Full FOrm of 'RCW' ..?
A. Run Callable Wrappers
B. Revised Code of Washington
C. Run time Callable Wrappers 
D. Run time Callable Writer
ANSWER: C

Which function is used to separate time from datetime ?
A. Split
B. Remove
C. CompareTo
D. None
ANSWER: A

What is an Object?
A. A combination of message and data 
B. A combination of namespace
C. A combination of task to be performed
D. A combination of Array
ANSWER: A

What is an Encapsulation?
A. An action or occurrence such as click
B. A package of one or more components together 
C. A set of statement that performs specific task
D. A reference type variable
ANSWER: B

The subscript number of an array starts from?
A. 0
B. 1
C. -1
D. 2
ANSWER: A

Which Escape Character is used for New Line in Console?
A. /n
B. \n 
C. //n
D. \n\r
ANSWER: B

Which is true? 1. There can be only one static constructor in the class. 2. The static constructor should be without parameters. 3. It can only access the static members of the class. 4. There should be no access modifier in static constructor definition.
A. 1 & 2
B. 2 & 3 & 4
C. 1 & 3 & 4
D. All the above
ANSWER: D

How can you sort the elements of the array in descending order?
A. System.Array.Clone()
B. By calling Sort() and then Reverse() methods.
C. By Calling Reverse()
D. By calling Sort()
ANSWER: B

Whats the difference between a Thread and a Process?
A. A process can have multiple threads in addition to the primary thread 
B. A process is code that is to be serially executed within a thread
C. When a process begins to execute, it continues until it is killed or until it is interrupted by a process with higher priority
D. No Difference, they are so same thing
ANSWER: A

Which of the following is Reference Type?
A. string 
B. bool
C. int
D. ushort
ANSWER: A

Which of the given method does not belong to System.Object?
A. Equals
B. Clone
C. GetType
D. ToString
ANSWER: B

Which property of the Exception class should you use to find a line of code that caused an exception to be thrown?
A. StackTrace
B. Data
C. Message
D. Source
ANSWER: A

Which type should you choose to identify a type that meets the following criteria: Always a number. Not greater than 65,535?
A. System.String
B. System.UInt16
C. System.IntPtr
D. Int
ANSWER: B

How do you prevent a class from being inherited?
A. Mark it as abstract
B. Mark it as static
C. Mark it as sealed 
D. Mark it as partial
ANSWER: C

Which copy Array.Clone() method perform?
A. Shallow Copy
B. Deep Copy
C. Hard Copy
D. None
ANSWER: A

What is the difference between Convert.Tostring() and ToString()?
A. both accept null values
B. convert.to string accept null values & tostring do not accept null values 
C. both do not accept null values
D. convert to string do not accept null values & tostring accept null values
ANSWER: D

The main reason to use operator overloading is...
A. To allow arithmetic operations to run more efficiently
B. To reduce the size of the executable program
C. To allow client code to be more concise and readable than it might be with regular methods 
D. None of above
ANSWER: C

The concept of parameterized datatypes like List is called in C# ...
A. Templates
B. Generics 
C. Delegates
D. Metatypes
ANSWER: B

There are five access levels in C#, private, internal, protected, protected internal, and public.
A. True 
B. False
C. Not applicable
ANSWER: A

Namespaces are used to ____ ?
A. Avoid name clashes between data types 
B. Create a unique name for an assembly
C. Separate assemblies
D. Not applicable
ANSWER: A

True or false: it is possible to use the const keyword on an reference parameter to prevent the method from modifying the parameter value.
A. True
B. False 
C. Not applicable
ANSWER: B

ICloneable interface is used to create new instance of the class with the same value as an existing instance?
A. Yes 
B. No
C. Not applicable
ANSWER: A

Which members can be accessed through an object reference?
A. Only the object class members
B. All members
C. No members
D. None of the Above
ANSWER: A

Which of these statements correctly declares a two-dimensional array in C#?
A. int[,] myArray;
B. int[][] myArray;
C. int[2] myArray;
D. System.Array[2] myArray
ANSWER: A

If a method is marked as protected internal who can access it?
A. Classes that are both in the same assembly and derived from the declaring class.
B. Only methods that are in the same class as the method in question.
C. Internal methods can be only be called using reflection.
D. Classes within the same assembly, and classes derived from the declaring class.
ANSWER : D

What is boxing?
A. Encapsulating an object in a value type.
B. Encapsulating a copy of an object in a value type.
C. Encapsulating a value type in an object.
D. Encapsulating a copy of a value type in an object.
ANSWER : D

What is a delegate?
A. A strongly typed function pointer.
B. A light weight thread or process that can call a single method.
C. A reference to an object in a different process.
D. An inter-process message channel.
ANSWER : A

A class that can not be inherited is what type of class?
A. Sealed
B. Static
C. Gather
D. Const
ANSWER: A

You want to log events generated by exception-handling code within your application, which will run on standalone systems running Windows 98 and Windows 2000. Which of the four methods of logging is the best single solution able to fulfill this requirement?
A. Windows event log
B. Custom log files
C. Databases such as SQL Server 2000
D. Email notifications
ANSWER: B

The statement that is used to replace multiple if statements is called
A. The switch & case statement
B. ?: (ternary operator)
C. The nestedif statement
D. The #endif statement
ANSWER: A

Which of the following is not a C# keyword?
A. Implements
B. If
C. Private
D. Delegate
ANSWER: A

what is the default access specifier for a Top-level Class, which are not nested into other Classes
A. public
B. private
C. protected
D. internal
ANSWER: D

If a method is marked as protected internal who can access it?
A. Access is limited to the current assembly
B. Access is limited to the containing class or types derived from the containing class.
C. Access is limited to the containing type
D. Access is limited to the current assembly or types derived from the containing class.
ANSWER: D

An array is a list of data items that _________________
A. all have the same type
B. all have different names
C. all are integers
D. all are originally set to ‘null’ (‘\0)
ANSWER: A

Which operator is used to allocate memory for an instance of a class, as well as to pass arguments to a constructor of that class?
A. new
B. delete
C. alloc
D. malloc
ANSWER: A

Can an Abstract class be declared as sealed?
A. True
B. False
ANSWER: A

An  instance of a derived class may be passed as an argument to a method that expects an instance of the base class.
A. True
B. False
ANSWER: A

Which of the following is a value type, and not a reference type?
A. array
B. delegate
C. enum
D. class
ANSWER: C

What does the parameter Initial Catalog define inside Connection String?
A. Password
B. User name
C. Database
D. Security
ANSWER: C

Are private class-level variables inherited?
A. No, because class is private.
B. Yes, but they are not accessible.
C. Yes, and you can access the variables.
D. Indeterminate.
ANSWER: B.

What is the difference between interface and abstract class?
A. An abstract class may only contain incomplete methods
B. An interface may contain complete or incomplete methods
C. A class may inherit several interfaces, A class may inherit only one abstract class
D. A class implementing an abstract class has to implement all the methods of the abstract class, but the same is not required in the case of an interface
ANSWER: B

How does assembly versioning in .NET prevent DLL Hell?
A. The runtime checks to see that only one version of an assembly is on the machine at any one time.
B. .NET allows assemblies to specify the name AND the version of any assemblies they need to run.
C. The compiler offers compile time checking for backward compatibility.
D. It is not possible.
ANSWER : B

Which of the following operations can you NOT perform on an ADO.NET DataSet?
A. A DataSet can be synchronised with the database.
B. A DataSet can be synchronised with a RecordSet.
C. A DataSet can be converted to XML.
D. You can infer the schema from a DataSet.
ANSWER: B

You have a TextBox control and a Help button that the user can press to get help on allowable values. You validate the data entered by the user in the TextBox control. If the user enters an invalid value, you set the focus back in the control using the Cancel property of the CancelEventArgs. A user reports that once he enters invalid data in the text box, he cannot click the Help button. What should you do to correct the problem?
A. Set the CausesValidation property of the text box to false.
B. Set the CausesValidation property of the text box to true.
C. Set the CausesValidation property of the Help button to false.
D. Set the CausesValidation property of the Help button to true.
ANSWER : C

What is the difference between an interface and an abstract class?
A. In a interface , all methods are abstract without implementation where as in an abstract class some methods we can define concrete.
B. In interface, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers.
C. Both A & B
D. Only A
ANSWER : C

What’s the implicit name of the parameter that gets passed into the set method/property of a class?
A.  Value
B.  Data
C.  Name
D.  None of these
ANSWER : A

What does the keyword “virtual” declare for a method or property?
A.  The method or property can be overridden.
B.  The method or property cannot be overridden.
C.  The method or property must be overridden.
D.  None of these
ANSWER : A

You can declare an override method to be static if the original method is not static.
A.  True
B.  False
ANSWER : B

What are the different ways a method can be overloaded?
A. Different parameter data types, different number of parameters, different return types.
B. Different parameter data types, different number of parameters, different order of parameters.
C. Different parameter data types, different name of parameters, different order of parameters.
D. None of these.
ANSWER : B

If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors then  you can enforce a call from an inherited constructor to a specific base constructor.
A.  True
B.  False
ANSWER : A

When do you absolutely have to declare a class as abstract?
A. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
B. When at least one of the methods in the class is abstract.
C. Both A & B
D. Only B
ANSWER : C

C# supports multiple-inheritance.
A.  True
B.  False
ANSWER : B

Private class-level variables can be inherited.
A.  True
B.  False
ANSWER : A

What does the term immutable mean?
A.  The data value may not be changed.
B.  The data value must not be changed.
C.  The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.
D.  Both A & C.
ANSWER : D

Whict is true for C#?
A. C# supports interfaces.
B. C# also provides support for structs.
C. C# provides component-oriented features
D. All
E. None
Answer:D

Does C# support multiple-inheritance?
A.No
B.Yes
Answer:A

Dot net has ________ access specifiers
A. 4
B. 5
C. 6
D. 3
ANSWER: B

Default access specifier for class is:
A. public
B. internal
C. both
D. none
ANSWER: B

Accessor is:
A. a method which retrieves a private value in an object.
B. a method which updates a private value in an object.
C. a method which updates a public value in an object
D. None
ANSWER: A

AbstractFactory means:
A. declares an interface for operations that create abstract products
B. implements the operations to create concrete product objects
C. declares an interface for a type of product object
D. defines a product object to be created by the corresponding concrete factory
ANSWER: A

You need to identify a type that meets the following criteriA. Is always a number. Is not greater than 65,535. Which type should you choose?
A. System.UInt16
B. int
C. System.String
D. System.IntPtr
Answer: A

You are working on a debug build of an application.You need to find the line of code that caused an exception to be thrown.Which property of the Exception class should you use to achieve this goal?
A. Data
B. Message
C. StackTrace
D. Source
Answer: C

You are developing a custom-collection class. You need to create a method in your class. You need to ensure that the method you create in your class returns a type that is compatible with the Foreach statement.Which criterion should the method meet?
A. The method must return a type of either IEnumerator or IEnumerable.
B. The method must return a type of IComparable.
C. The method must explicitly contain a collection.
D. The method must be the only iterator in the class.
Answer: A

You need to select a class that is optimized for key-based item retrieval from both small and large collections. Which class should you choose?
A. OrderedDictionary class
B. HybridDictionary class
C. ListDictionary class
D. Hashtable class
Answer: B

You are creating a class that uses unmanaged resources. This class maintains references to managed resources on other objects.You need to ensure that users of this class can explicitly release resources when the class instance ceases to be needed. Which three actions should you perform? (Each correct Answer presents part of the solution. Choose
three.)
A. Define the class such that it inherits from the WeakReference class.
B. Define the class such that it implements the IDisposable interface.
C. Create a class destructor that calls methods on other objects to release the managed resources.
D. Create a class destructor that releases the unmanaged resources.
E. Create a Dispose method that calls System.GC.Collect to force garbage collection.
F. Create a Dispose method that releases unmanaged resources and calls methods on other objects torelease the managed resources.
Answer: (B AND D AND F)

You use Reflection to obtain information about a method named MyMethod. You need to ascertain whether MyMethod is accessible to a derived class. What should you do?
A. Call the IsAssembly property of the MethodInfo class.
B. Call the IsVirtual property of the MethodInfo class.
C. Call the IsStatic property of the MethodInfo class.
D. Call the IsFamily property of the MethodInfo class.
Answer: D

You are creating a class that uses unmanaged resources. This class maintains references to managed resources on other objects. You need to ensure that users of this class can explicitly release resources when the class instance ceases to be needed. Which three actions should you perform? (Each correct answer presents part of the solution. Choose three.)
A. Define the class such that it inherits from the WeakReference class.
B. Define the class such that it implements the IDisposable interface.
C. Create a Dispose method that releases unmanaged resources and calls methods on other objects to release the managed resources.
D. Create a class destructor that releases the unmanaged resources.
Answer: B, C, D

You are working on a debug build of an application. You need to find the line of code that caused an exception to be thrown. Which property of the Exception class should you use to achieve this goal?
A. Data
B. Message
C. StackTrace
D. Source
Answer: C

You are developing a custom-collection class. You need to create a method in your class. You need to ensure that the method you create in your class returns a type that is compatible with the Foreach statement. Which criterion should the method meet?
A. The method must return a type of either IEnumerator or IEnumerable.
B. The method must return a type of IComparable.
C. The method must explicitly contain a collection.
D. The method must be the only iterator in the class.
Answer: A

Assume that a class, Class1, has both instance and static constructors. Given the code below, how many times will the static and instance constructors fire?Class1 c1 = new Class1();Class1 c2 = new Class1();Class1 c3 = new Class1();
A. STATIC: 1 , INSTANCE1 
B. STATIC: 1 , INSTANCE3
C. STATIC: 3 , INSTANCE3
D. NONE
ANSWER: B

1 comment: