🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

chapter 7-23_merged.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Document Details

Tags

C# programming object-oriented programming software development

Full Transcript

Microsoft Visual C# Step by Step Chapter 07: Creating and managing classes and objects Q1. __________ provide a convenient mechanism for modeling the entities manipulated by applications. A. Classes B. Objects C. Namespaces D. Enumerations Answer: A Q2. Encapsulation is sometimes referr...

Microsoft Visual C# Step by Step Chapter 07: Creating and managing classes and objects Q1. __________ provide a convenient mechanism for modeling the entities manipulated by applications. A. Classes B. Objects C. Namespaces D. Enumerations Answer: A Q2. Encapsulation is sometimes referred to as ________________ A. polymorphism B. abstraction C. grouping D. information hiding Answer: D Q3. What are the purposes of encapsulation? A. To combine methods and data inside a class B. To control the accessibility of the methods and data C. To protect data from malicious use D. To hide objects from applications Answer: A, B Q4. Which keyword is used to create new instance of a class? A. create B. open C. new D. object Answer: C Q5. The variables in a class are called ______________. A. properties B. fields C. methods D. constructors Answer: B Q6. What is an object? A. The definition of a type B. An instance of a class C. A member of a class D. Information that a class holds Answer: B Q7. Which access modifier makes a method or field of a class accessible only from within the class? A. public B. internal C. protected D. private 1 Answer: D Q8. Which access modifier makes a method or field of a class accessible both within and from outside the class.? A. public B. internal C. protected D. private Answer: A Q9. Which access modifier makes a method or field of a class accessible from within the class and the derived classes? A. public B. internal C. protected D. private Answer: C Q10. What is a constructor of a class? A. a special method that runs automatically when you create an instance of a class B. a member that shared among all instances of a class C. a method that can be invoked without creating an instance D. a special method that is called just before when an object is destroyed from memory Answer: A Q11. Which of the following is not true about constructors? A. A Constructor is a special method called automatically when a new instance of the class is created B. A constructor has the same name as the class C. A constructor has no return type D. A constructor cannot take parameters Answer: D Q12.What happens if you do not write any constructor for your class? A. You cannot create objects from the class B. You class does not compile C. The compiler generates a default constructor for you D. You class is treated as a structure Answer: C Q13. Constructors do not support overloading. A. True B. False Answer: B Q14. What is a deconstructor in a class? A. a special method that runs automatically when you create an instance of a class B. a special method that is called just before when an object is destroyed from memory C. a special method that enables you to examine an object and extract the values of its fields D. a member that shared among all instances of a class Answer: C [Don't confuse with destructor with deconstructor. Deconstructor is a new feature] Q15. Which of the following is not true about a deconstructor in a class? 2 A. It is always named Deconstruct and It must be a void method. B. It must take one or more parameters C. It can be parameter less D. The parameters are marked with the out modifier Answer: C Q16. Which of the following is not true about static members? A. static members are class members rather than object (instance) member B. To access static member, you do not need to create object C. static members are shared D. From a static method you can access both static and non-static fields Answer: D Q17. Only one copy of a static member is created irrespective of how many object is created. A. True B. False Answer: B Q18. How do you create a field is static but that its value can never change? A. By prefixing the field with the const keyword B. By prefixing the field with the const and static keyword C. By prefixing the field with the protected keyword D. By prefixing the field with the internal keyword Answer: A Q19. A static class can contain both static and non-static members. A. True B. False Answer: B Q20. Which one creates an anonymous class correctly? A. var person = new [] {“Ahmed Ali”, “[email protected]”}; B. var person = new {“Ahmed Ali”, “[email protected]”}; C. var person = new {Name=“Ahmed Ali”, Email=“[email protected]”}; D. person = new {Name=“Ahmed Ali”, Email=“[email protected]”}; Answer: C Q21. Which one is not true for an anonymous class? A. can contain only public fields B. fields cannot be static C. fields must be initialized D. can contain only public methods Answer: D [You cannot define any methods for an anonymous class] 3 Microsoft Visual C# Step by Step Chapter 08: Understanding values and reference Q1. Which of the following is NOT a value type? A. int B. Boolean C. string D. Char Answer: C Q2. Consider the method void ChangeValue( int i ) { i++; } Now consider the following statements int a=10; ChangeValue( a ); Console.WriteLine( a ); What is the output? A. 0 B. 10 C. 11 D. null Answer: B Q3. Value types are sometime called ________________ A. direct type B. indirect type C. structures D. enumerations Answer: A Q4. Reference types are sometime called ________________ A. direct type B. indirect type C. structures D. enumerations Answer: B Q5. Consider the statement System.Windows.Forms.TextBox t; What value does the reference t hold? A. empty B. 0 C. null 1 D. nothing Answer: C Q6. Consider the two statements Statement I: int i=null; Statement II: Object o = null; Now which statement or statements are valid? A. Statement I B. Statement II C. Both Statement I and Statement II D. Neither of the two Answer: B Q7. Which one is nullable type? A. Object o; B. int i; C. int? i; D. int?? i; Answer: C Q8. Which properties a nullable type has? A. IsNull B. HasValue C. Value D. Null Answer: B, C Q9. Consider the code snippet static void DoWork(out int param) { param++; } Will this compile? A. Yes B. No Answer: B Q9. Converting a value type into reference type is called______ A. casting B. explicit casting C. boxing D. unboxing Answer: C Q9. Converting a reference type into value type is called______ A. casting B. explicit casting C. boxing D. unboxing 2 Answer: D Q10. Which operator is used to test whether the specified cast is valid? A. = B. == C. ? D. is Answer: D 3 Microsoft Visual C# Step by Step Chapter 09: Creating value types with enumerations and structures Q1. C# allows creating two user defined value types. They are: A. delegates B. objects C. structures D. enumerations Answer: C, D Q2. ____________ is a set of values with symbolic names. A. An enumeration B. An indexer C. A delegate D. An array Answer: A Q3. Enumeration variable live on ___________. A. the stack B. the heap C. unmanaged memory D. none of the above Answer: A Q4. Which operators can be used on enumeration variables? A. Many of the standard operators that you can use on integer variables B. Bitwise operators C. Shift operator D. All of the above Answer: A Q5. By default, the Integer value associated with the first element of an enumeration is ____. A. 0 B. 1 C. Null D. No default, you have to specify one Answer: A Q6. Underlying type of an enumeration is always ______ A. integral type B. floating type C. string type D. reference type Answer: A Q7. Underlying type of an enumeration defaults to_______ A. short B. int C. long 1 D. float Answer: B Q8. ____ is like a class but is a value type. A. An enumeration B. A delegate C. An event D. A structure Answer: D Q9. Which one of the following built-in types is not a structure? A. Boolean B. Int32 C. Single D. String Answer: D Q10. You can use operators such as the equality operator (==) and the inequality operator (!=) on your own structure type variables since they are value types. A. True B. False Answer: B [you cannot use operators such as the equality operator (==) and the inequality operator (!=) on your own structure type variables even though they are value types] Q11. You can declare a default constructor (a constructor with no parameters) for a structure A. Yes B. No Answer: B [No, you cannot] Q12. If you declare your own constructor in a structure, will the compiler still generate the default constructor? A. True B. False Answer: A [This is not true for classes] 2 Microsoft Visual C# Step by Step Chapter 10: Using arrays Q1. What is an array? A. An array is an ordered sequence of items. B. An array is an unordered sequence of items. C. An array is a set of items stored in sequence of key. D. An array is a sequence of database records. Answer: B Q2. Which one true about an array? A. All the items in an array have the same type B. Each item in an array is of different type C. All the items in an array are value types D. All the items in an array reference type Answer: A Q3. Which one is not true about an array? A. All the items in an array have the same type B. The items in an array live in a contiguous block of memory and are accessed by using an index C. An array itself is a value type D. An array can store both the value type and the reference type Answer: C Q4. An item in an array are accessed by using _____________. A. Its index B. Its key C. Its name D. offset from the starting item Answer: A Q5. Which one correctly declares an array? A. int pins[]; B. int[] pins; C. int pins; D. int() pins; Answer: B Q6. When you create an array instance, all the elements of the array are initialized to ______________________. A. null B. a default value depending on their type C. random value D. empty Answer: B Q7. All numeric values default to ________. A. 0 B. -1 C. null D. random value 1 Answer: A Q8. What is the default value of an object? A. Empty B. Null C. Empty structure D. None of the above Answer: B Q9. Which symbol signifies an array? A. ( ) B. { } C. [ ] D. < > Answer: C Q10. Arrays are _______________________. A. reference types B. value types C. structures D. nullable structures Answer: A Q11. For array items memory is allocated to heaps. A. True B. False Answer: A Q12. You can create an array whose size is 0. A. True B. False Answer: A Q13. Which one of the following statements will work? A. int[] pins = new int{ 9, 3, 7, 2 }; B. int[] pins = new int{ 9, 3, 7 }; C. int[] pins = new int{ 9, 3, 7, 2 }; D. int[] pins = new int {}; Answer: C Q14. Which one is an implicitly typed array? A. int[] pins = new int[] {5, 6, 7}; B. var pins = new int[] {5, 6, 7}; C. var pins = new int {5, 6, 7}; D. var pins = new [] {5, 6, 7}; Answer: D Q15. What will be the result of the following statement? var bad = new [] {"John", "Diana", 99, 100}; A. An array of four string will be created B. An array of four object will be created C. An array of two string will be created and two items 99 and 100 will be discarded D. A compile-time error “No best type found for implicitly-typed array” will be reported Answer: D Q16. What will be the result of the following statement? 2 var numbers = new []{1, 2, 3.5, 99.999}; A. An array of four integers will be created B. An array of four doubles will be created C. An array of two integers will be created and two items 3.5 and 99.999 will be discarded D. A compile-time error “No best type found for implicitly-typed array” will be reported Answer: B Q17. If you specify an index that is less than 0 or greater than or equal to the length of the array, what happens? A. null value is returned B. 0 is returned C. an IndexOutOfRangeException exception is thrown D. compiler reports a warning Answer: C Q18. All arrays are actually instances of the ________ class. A. System.object B. System.ValueType C. System.Array D. System.Collection Answer: C Q19. If you want to iterate through only a known portion of an array or bypass certain elements, it’s easier to use______________. A. a foreach statement B. a for statement C. an enumerator D. an iterator Answer: B Q20. Which one should you use if you need to modify the elements of the array? A. a for statement B. a foreach statement C. an enumerator D. an iterator Answer: A Q21. Which one is a jagged array? A. int[] numbers = new int; B. int[,] numbers = new int[3, 2]; C. int[,] numbers = new int[3,]; D. int[][] numbers = new int[]; Answer: D 3 Microsoft Visual C# Step by Step Chapter 11: Understanding parameter arrays Q1. In which case parameter arrays are useful? A. if you want to write methods that can take any number of arguments B. if you want to write methods that can take an array C. if you want to write methods that can return multiple values D. if you want to write methods that can take value types only Answer: A Q2. Which one is overloading? A. declaring a method with the same name in both the base class and the derived class B. declaring two or more methods with the same name in the same scope C. declaring two class with the same name in two namespaces D. none of the above Answer: B Q3. Which one is a variadic method? A. a method that takes a variable number of arguments B. a method that takes an array argument C. a method that return a variable number of values D. a method that returns an array Answer: A Q4. Why do you use the ArgumentException class? A. It is intended to be thrown by a method which is marked protected but accessed from public scope B. It is intended to be thrown by a method if it is accessed illegally C. It is intended to be thrown by a method if the arguments supplied do not meet the requirements of the method D. It is intended to be thrown by a method which is static but invoked using object reference Answer: C Q5. You can use the params keyword with multidimensional arrays. A. True B. False Answer: B Q6. You can overload a method based solely on the params keyword. A. True B. False Answer: B Q7. Are the following two methods in the same class possible? public static int Min(int[] paramList) {...} public static int Min(params int[] paramList) {...} A. Yes B. No Answer: B Q8. You are allowed to specify the ref or out modifier with params arrays. A. True B. False Answer: B 9. Should the following two methods compile? public static int Min(ref params int[] paramList)... 1 public static int Min(out params int[] paramList) … A. Yes B. No Answer: B Q10. Is the following method valid? public static int Min(params int[] paramList, int i) … A. Yes B. No Answer: B Q11. Consider the code below class Black { public static void Hole(params object[] paramList){...}... } Now which one of the following is not a valid call the Hole method? A. Black.Hole(); B. Black.Hole(null); C. Black.Hole(“forty two”, 42); D. Black.Hole(x=>x+1); Answer: D 2 Microsoft Visual C# Step by Step Chapter 12: Working with inheritance Q1. Which feature of object-oriented programming you can use as a tool to avoid repetition when defining different classes that have some features in common and are quite clearly related to one another? A. Inheritance B. Polymorphism C. Encapsulation D. Multithreading Answer: A Q2. Inheritance in programming is _________. A. an association of classes B. a relationship between classes C. merging two class D. whole-part relationship Answer: B Q3. Which one correctly defines the DerivedClass inherits from the BaseClass? A. class DerivedClass : BaseClass {... } B. class BaseClass : DerivedClass {... } C. class DerivedClass extends BaseClass {... } D. class DerivedClass inherits BaseClass {... } Answer: A Q4. C# inheritance is always implicitly ______. A. public B. protected C. internal D. private Answer: A Q5. Inheritance applies ______. A. only to classes B. only to structures C. both to classes and to structures D. none of the above Answer: A Q6. In C#, a class is allowed to derive from two or more classes. A. True B. False Answer: B Q7. Which one is the root class of all classes? A. System B. System.Object C. System.ValueType D. System.MarshalByRefObject Answer: B Q8. The fields in a class require initialization when an object is created. Where in a class, do you perform this kind of initialization? A. In a constructor B. In a property C. In a destructor D. In a method Answer: A 1 Q9. Which keyword do you use to call a base-class constructor? A. super B. this C. parent D. base Answer: D Q10. What happens If you don’t explicitly call a base-class constructor in a derived-class? A. The fields in base class are not initialized B. The compiler attempts to silently insert a call to the base class’s default constructor before executing the code in the derived-class constructor C. The System.Object class's constructor is called executing the code in the derived-class constructor D. The compiler generates error and you code will not compile Answer: B Q11. Consider the class definitions class Mammal {... } class Horse : Mammal {... } class Whale : Mammal {... } Now find out which assignment is illegal? A. Horse myHorse = new Horse(...); B. Whale myWhale = new Whale(...); C. Mammal myWhale = new Whale(...); D. Horse myHorse = new Mammal(...); Answer: D Q12. A method in a derived class ____________ a method in a base class that has the same signature. A. hides B. overrides C. overloads D. none of the above Answer: A Q13. A method that is intended to be overridden is called a ___________ method. A. virtual B. static C. shared D. sealed Answer: A Q14. ___________a method is a mechanism for providing different implementations of the same method in derived classes? A. Overloading B. Overriding C. Hiding D. Masking Answer: B Q15. A virtual method can be private. A. True B. False 2 Answer: B Q16. Which one is not true about virtual and overridden methods? A. An override method is implicitly virtual and can itself be overridden in a further derived class B. A virtual method can be private C. A virtual method can be protected D. The signatures of the virtual and override methods must be identical Answer: B Q17. Which access modifier allows access to members from the class and the derived classes? A. public B. internal C. protected D. private Answer: C Q18. Which one is appropriate if you need to quickly extend a type by adding a method without affecting existing code? A. using inheritance B. using overloading C. using overriding D. using extension methods Answer: D Q19. How can you extend an existing type (a class or a structure) with additional static methods? A. Using extension methods B. Using inheritance C. Using interface D. Using overloading and overriding Answer: A Q20. You define an extension method in a ________ class. A. static B. non-static C. abstract D. sealed Answer: A Q21. The first parameter of an extension method must be ________________________________________. A. Value type B. Reference type C. Nullable type D. the type to which the method applies Answer: D 3 Microsoft Visual C# Step by Step Chapter 03: Creating interfaces and defining abstract classes Q1. __________does not contain any code or data; it just specifies the methods and properties that a class that implements it must provide. Which one correctly fits the blank space? A. An enumeration B. A structure C. An interface D. An abstract class Answer: C Q2. Which one of the following enables you to completely separate the names and signatures of the methods of a class from the method’s implementation? A. An enumeration B. A structure C. An interface D. An abstract class Answer: C Q3. Which one of the following are similar to interfaces in many ways? A. An enumeration B. A structure C. A delegate D. An abstract class Answer: D Q4. What is the difference between an interface and an abstract class? A. An interface contains only abstract methods and properties whereas an abstract class contains only concrete methods and properties B. An interface contains only concrete methods and properties whereas an abstract class contains only abstract methods and properties C. An interface contains only abstract methods and properties whereas an abstract class contains both concrete and concrete methods and properties D. An interface contains both abstract and concrete methods and properties whereas an abstract class contains only abstract methods and properties Answer: C Q5. If a class implements an interface, __________________. Which phrase appropriately fits the blank space? A. the interface guarantees that the all instances of the class are created only using the default constructor 1 B. the interface guarantees that the class contains all the methods specified in the interface. C. the interface guarantees that all methods of the the class can be called without created any instance D. the interface guarantees that the class cannot be inherited further Answer: B Q6. _____________does not contain any code or data. A. An interface B. An abstract class C. A static class D. A sealed class Answer: A Q7. In an interface you define ________________________ A. the name, return type, parameters and the body of the method B. only the name, return type, and parameters of the method, not the method body C. only the name, parameters of the method D. only the name, return type of the method Answer: B Q8. The interface describes ___________________________________. A. the functionality that a class should provide B. how this functionality is implemented C. all of the above D. none of the above Answer: B Q9. Which one is true for an interface? A. An interface gives you the name, return type, parameters and implementation of the method B. An interface gives you only the name, return type, and parameters of the method but no implementation C. An interface gives you the name, return type, and parameters of the method and sometimes default implementation of the method D. An interface gives you only properties but no method Answer: B Q10. Which one is not true for an interface? A. You define methods without any access modifier B. The methods in an interface have no implementation C. You can add virtual keywords to methods in an interface D. All methods in an interface are implicitly public Answer: C Q11. Which interface definition is correct? A. interface ILandBound { public int NumberOfLegs(); } 2 B. interface ILandBound { public virtual int NumberOfLegs(); } C. interface ILandBound { int NumberOfLegs() { return 0; } } D. interface ILandBound { int NumberOfLegs(); } Answer: D [You cannot add access modifier or virtual keyword to methods in interfaces. All methods in interfaces are implicitly public and virtual. Interface methods cannot have method body.] Q12. All methods in an interface are implicitly ______________. A. public B. private C. protected D. internal Answer: A Q13. Which rule is not required to meet, when you implement an interface? A. The method names and return types match exactly B. Any parameters (including ref and out keyword modifiers) match exactly C. The methods have override keyword D. All methods implementing an interface must be publicly accessible if you are using an explicit interface implementation Answer: C Q15. The Horse class inherits from the Mamma class and implements ILandBound. How do you define it? A. class Horse : Mammal , ILandBound {... } B. class Horse : Mammal , ILandBound {... } C. class Horse : ILandBound, Mammal {... } D. class Horse : Mammal inherits ILandBound { 3... } Answer: A Q16. Which statement is true? A. A class can have one base class, but it is allowed to implement an unlimited number of interfaces. B. A class can have multiple base classes but it is allowed to implement one interface. C. A class can have one base class, and it is allowed to implement one interface. D. A class can have multiple one base classes, but it is allowed to implement multiple interfaces. Answer: A Q17. Which one is not true? A. You’re not allowed to define any fields in an interface, not even static fields. B. You’re not allowed to define a destructor in an interface. C. You cannot specify an access modifier for any method. D. An interface is not allowed to inherit from an interface. Answer: D Q18. An interface is not allowed to inherit from a structure or a class, although an interface can inherit from another interface. A. True B. False Answer: A Q19. A class is allowed to implement an unlimited number of interfaces. A. True B. False Answer: A Q20. You can use public access modifier to a method when you explicitly implementing an interface. A. True B. False Answer: B Q21. You are allowed to define any fields in an interface, not even static fields. A. True B. False Answer: B Q22. You are allowed to define a default constructor in an interface. A. True B. False Answer: B Q23. You cannot specify an access modifier for any method in an interface. A. True B. False Answer: A 4 Q24. You cannot create an instance of an abstract class. A. True B. False Answer: A Q25. How can you prevent a class from being used as a base class? A. By adding the abstract keyword B. By adding the sealed keyword C. By adding the private keyword D. By adding the protected keyword Answer: C Q26. Which class cannot be inherited? A. abstract class B. private class C. static class D. sealed class Answer: D Q27. Which method a derived class cannot override? A. abstract method B. static method C. protected method D. sealed method Answer: D Q28. A ________is the first implementation of a method A. virtual method B. sealed method C. abstract method D. overridden method Answer: A Q29. A ________is the last implementation of a method A. virtual method B. sealed method C. abstract method D. overridden method Answer: B 5 Microsoft Visual C# Step by Step Chapter 14: Using garbage collection and resource management Q1. How memory allocated for the value types are reclaimed? A. Value types are destroyed and their memory reclaimed when the program exits. B. Value types are destroyed and their memory reclaimed when they go out of scope. C. Value types are not destroyed and their memory are not reclaimed unless you they are set to null. D. None of the above Answer: B Q2. You create an object by _____________________. A. using create operator B. using the new operator C. calling constructor D. all of the above Answer: B Q3. The process of destroying an object and returning memory back to the heap is known as ________. A. Memory management B. Resource collection C. Garbage collection D. Destruction Answer: C Q4. What happens when an object is no longer is being actively referenced? A. It is destroyed and he memory that it is using is reclaimed as soon as it goes out of scope B. It resides in memory as long as the program executes C. It resides in memory unless you explicitly nullify it D. It is destroyed and the memory that it is using is reclaimed by garbage collection process Answer: D [Value types are destroyed and their memory reclaimed when the program exits.] Q5. In many of these cases, writing a destructor is unnecessary. Why? A. The CLR does not guarantee to call destructor every time an object is destroyed B. The CLR will automatically clear up any managed resources that an object uses C. The CLR prefer the dispose method to destructor D. All of the above Answer: B Q6. When a destructor can prove useful? A. if an object references an unmanaged resource, either directly or indirectly B. if an object has asynchronous methods C. if an object has long running methods D. if an object using uses database connections Answer: A Q7. Which symbol precedes before the destructor in a class? A. A hash(#) 1 B. A pipe(|) C. A tilde (~) D. A minus (-) Answer: C Q8. You can declare a destructor in a value type, such as a struct. A. True B. False Answer: B Q9. You never declare a destructor with parameters A. True B. False Answer: B Q10. The process of destroying an object and returning memory back to the heap is known as ________ A. Memory management B. Resource collection C. Garbage collection D. Destruction Answer: C Q11. What is a destructor? A. A destructor is a special method that is called when you call dispose method B. A destructor is a special method, a little like a constructor, except that the CLR calls it after the reference to an object has disappeared C. A destructor is a protected method that called by derived class to dereference the base class’s resources D. There is no destructor concept in C# Answer: B Q12. How can you release the resource yourself as quickly as possible? A. by defining destructors B. by creating a disposal method C. by overriding, finalize method D. None of the above Answer: B Q13. The _______ statement provides a clean mechanism for controlling the lifetimes of resources A. do B. using C. switch D. checked Answer: B Q14. How can you call a destructor? A. By calling the dispose method B. Setting object reference to null C. By calling GC.Collect method D. You can’t call a destructor. Only the garbage collector can call a destructor Answer: D Q15. How can you can force garbage collection? A. By calling the dispose method on an object B. By Setting object reference to null C. By calling GC.Collect method 2 D. You can’t force garbage collection Answer: C Q16. How can you support exception-safe disposal in a class? A. By writing a constructor in the class B. By writing a destructor in the class C. By providing a dispose method in the class D. By implementing the IDisposable interface Answer: D 3 Microsoft Visual C# Step by Step Chapter 15: Implementing properties to access fields Q1. It looks like a field but acts as a method. What is it? A. An event B. A property C. A constructor D. A static property Answer: B Q2. Calling a method to achieve the effect on a field feels a little clumsy. What then does alleviate this awkwardness? A. Properties B. Events C. Constructors D. All of the above Answer: A Q3. What is a property of a class? A. A property is a cross between a field and the constructor B. A property is a cross between a field and a method C. A property is a bridge between a field and its consumer D. None of the above Answer: B Q4. ______________looks like a field but acts like a method. A. A Property B. A method C. A public field D. An Event Answer: A Q5. A property has two blocks of code. what are they? A. read and write B. in and out C. get and set D. push and pop Answer: C Q6. The _______ block in a property contains statements that run upon writing to the property. A. get B. set C. put D. write Answer: B Q7. Which special variable holds the value assigned to the set accessor of a property? A. data B. value C. args D. param Answer: B Q8. Which one is a read-only property? A. The property that contains only get block B. The property that contains only set block C. The property that contains both get and set block D. None of the above 1 Answer: A Q9. Which one is a write-only property? A. The property that contains only get block B. The property that contains only set block C. The property that contains both get and set block D. None of the above Answer: B Q10. You can use a property as a ref or an out argument to a method. A. True B. False Answer: B Q11. The get and set accessors can take any parameters. A. True B. False Answer: B Q12. Which one uses automatic property feature? A. class Circle { int _radius; public int Radius { get => this.; set => this._radius = value; } } B. class Circle { int _radius; public int Radius { get {return this_radius;} set {this._radius = value; } } } C. class Circle { public int Radius { get; set; } } D. class Circle { public int Radius{ } } Answer: C Q13. Consider the class class Circle { public int Radius { get; set; } } Now which one use automatic object initializer? A. Circle c = new Circle(); c.Radius = 3; B. Circle c = new Circle { Radius = 3 }; C. Circle c = new Circle [ Radius = 3 ]; D. Circle c = new Circle (3); Answer: B 2 Microsoft Visual C# Step by Step Chapter 16: Handling binary data and using indexers Q1. Which one can be thought of a smart array? A. Generic collection B. LinkedList C. Indexer D. Bitwise operators Answer: C Q2. An indexer encapsulates ________________. Which one best fits the blank space? A. a single value B. a set of values C. a single object D. an enumeration Answer: B Q3. Which one uses the same as the syntax that you use for an array? A. Enumeration B. Structure C. Indexer D. Collection Answer: C Q4. How do you indicate that a constant should be treated as a binary representation? A. By prefixing 0x B. By prefixing 2x C. By prefixing 0b D. By prefixing 0b0 Answer: D Q5. Which one correctly the following code assigns the binary value 1111 (15 in decimal) to a variable? A. uint binData = b01111 B. uint binData = 0x01111 C. uint binData = b01111 D. uint binData = 0b01111 Answer: D Q6. Which one of the following code shows the binary representations of a integer? A. int n = 15; Console.WriteLine(Convert.ToBase64String(n)); B. int n = 15; Console.WriteLine(Convert.ToString(n,0b0)); C. int n = 15; Console.WriteLine(Convert.ToString(n,2)); D. int n = 15; Console.WriteLine(Convert.ToString(n,0)); Answer: C Q7. Which bitwise operator C# does not support? A. & B. | C. > Answer: D 1 Q8. Which one is bitwise XOR operator? A. D. Func Answer: B Q6. You have a delegate delegate int Calculate(int x, int y) Which one of the following methods the cannot be invoked using the above delegate? A. void Process(int x, int y) {...} B. int Add(int m, int n) {...} C. int Mod(int n, int d) {...} D. int Compare(int p, q) {...} Answer: A 1 [return type and parameters type and order must match] Q7. What happens if you use the += operator on an uninitialized delegate? A. A run-time error will be thrown B. A compilation error will be thrown C. The delegate will be initialized automatically D. The compiler will ignore the statement Answer: C Q8. Which operator do you use to add methods to a delegate? A. + B. & C. += D. &= Answer: C Q9. Which operator do you use to unsubscribe a method from a delegate? A. - B. -= C. |= D. ~= Answer: B Q10. In. NET, an event is always _________? A. a delegate B. a method C. an object D. a Func delegate Answer: A Q11. Which one is the correct syntax to declare an event? A. delegateTypeName eventName B. delegateTypeName event eventName C. event delegateTypeName eventName D. public delegateTypeName eventName Answer: C 2 Microsoft Visual C# Step by Step Chapter 21: Querying in-memory data by using query expressions Q1. What does LINQ stand for? A. Language-International Query B. Language-Internal Query C. Language-Integrated Query D. Local-Integrated Query Answer: C Q2. Which one is true about LINQ? A. It abstracts the mechanism that an application binds data to UI controls B. It abstracts the mechanism that an application accesses data from application C. It abstracts the mechanism that an application applies logic to process data in applications D. It abstracts the mechanism that an application uses to query data from application code itself Answer: D Q3. To which data LINQ query can be applied? A. arrays only B. collections that implements IList only C. genetic collections only D. any data structure that implements the IEnumerable or IEnumerable interface Answer: D Q4. Which LINQ query is not valid? A. var result = customers.Select(c => c. FirstName); B. var result = customers.Select(c => c. First Name, c.LastName); C. var result = customers.Select(c => $"{c.FirstName} {c.LastName}"); D. var result = customers.Select(c => new {C.FirstName, c.LastName}"); Answer: B Q5. Which LINQ extension method do you use to project specific fields from an enumerable collection? A. Get B. ToList C. Select D. Query Answer: C Q6. Which LINQ method do you use to filter rows from an enumerable collection? A. Select B. Filter C. Where D. Pick Answer: C Q7. Which LINQ query returns the name of each company in the addresses array in ascending order? A. var companyNames = addresses.Select(c => c.CompanyName).OrderBy(x => x.CompanyName B. var companyNames = addresses.OrderBy(x => x.CompanyName).Select(c => c.CompanyName); 1 C. var companyNames = addresses.Order(x => x.CompanyName).Select(c => c.CompanyName); D. var companyNames = addresses.Select(c => c.CompanyName).Sort(x => x.CompanyName Answer: B Q8. Which LINQ query returns the name of each company in the addresses array in descending order? A. var companyNames = addresses.Select(c => c.CompanyName).OrderBy(x => x.CompanyName descending) ; B. var companyNames = addresses.OrderBy(x => x.CompanyName desc).Select(c => c.CompanyName); C. var companyNames = addresses.OrderByDescending(x => x.CompanyName).Select(c => c.CompanyName); D. var companyNames = addresses.Select(c => c.CompanyName).Sort(x => x.CompanyName DESC) ; Answer: B Q9. Which LINQ extension method does not return a single scalar value rather returns an enumerable collection? A. Count B. Avg C. Max D. Select Answer: D Q10. Which one is a LINQ query using query operators? A. var customerFirstNames = customers.Select(cust => cust.FirstName) B. var customerFirstNames = from cust in customers select cust.FirstName C. var custs = customers.ToList() D. All of the above Answer: B Q11. Which one is a valid LINQ query? A. var countriesAndCustomers = from a in addresses join c in customers on a.CompanyName == c.CompanyName select new { c.FirstName, c.LastName, a.Country }; B. var countriesAndCustomers = from a in addresses join c in customers on a.CompanyName equals c.CompanyName select new { c.FirstName, c.LastName, a.Country }; C. var countriesAndCustomers = from a in addresses join c in customers on a.CompanyName.Equals( c.CompanyName) select new { c.FirstName, c.LastName, a.Country }; D. All of the above Answer: B [you must use equals operator with on] Q12. How can you force evaluation of a LINQ query when it is defined and generate a static, cached collection? 2 A. Use method-based query instead of using query operators B. Use query operators in query expression C. Call ToList method on query result D. Call ForEach method on query result Answer: C Q13. Which method do you use to force immediate generation of the results for a LINQ query? A. ToArray B. Take C. Select D. Join Answer: A [use ToList or ToArray] Q14. What should you do to project specified fields from an enumerable collection? A. Use the ToList method and specify a lambda expression that identifies the fields to project. B. Use the Select method and specify a lambda expression that identifies the fields to project. C. Use the GroupBy method and specify a lambda expression that identifies the fields to project. D. Use the Skip and Take methods Answer: B 3 Microsoft Visual C# Step by Step Chapter 23: Improving throughput by using tasks Q1. The ability to do more than one thing at the same time is referred to as A. Multitasking B. Synchronizing C. Asynchronous programming D. Threading Answer: A Q2. What is the Task class is for? A. The Task class is the replacement of old Thread class B. The Task class is an abstraction of a concurrent operation C. The Task class is an abstraction of a Asynchronous operation D. The Task class is the main class for WUP apps Answer: B Q3. How can you run multiple block of code run in parallel in windows store app? A. Using Task object B. Using Three class C. Using ThreadPool class D. Using async method Answer: A Q4. How can you arrange for another task to be scheduled immediately when a task completes? A. Call the ContinueWith method of a Task object B. Call the StartAfter method of a Task object C. Call the Run method of a Task object D. None of the above Answer: A Q5. Consider the code snippet Task task = new Task(doWork); task.Start(); Task newTask = task.ContinueWith(doMoreWork); What does the above code block do? A. The above code example creates a Task object that runs the doWork method and specifies a continuation that runs the doMoreWork method in a new task when the first task completes B. The above code example creates a Task object that runs the doWork method and specifies a continuation that runs the doMoreWork method in a new task without waiting for the completion of the first task C. The above code example creates a Task object that runs the doWork method and specifies a continuation that runs the doMoreWork method in a new task if the first task fails to complete D. The above code example creates a Task object that runs the doWork method and specifies a continuation that runs the doMoreWork method in a new task only if the first task completes successfully Answer: A Q6. Which code add a continuation to a task that runs only if the initial action does not throw an unhandled exception? 1 A. Task task = new Task(doWork); task.ContinueWith(doMoreWork, TaskContinuationOptions. OnlyOnRanToCompletion); task.Start(); B. Task task = new Task(doWork); task.ContinueWith(doMoreWork, TaskContinuationOptions.NotOnFaulted); task.Start(); C. Task task = new Task(doWork); task.ContinueWith(doMoreWork, TaskContinuationOptions. OnlyOnCanceled); task.Start(); D. Task task = new Task(doWork); task.ContinueWith(doMoreWork, TaskContinuationOptions. NotOnRanToCompletion); task.Start(); Answer: B Q7. Which code add a continuation to a task that runs only if the initial action either be canceled or throw an unhandled exception? A. Task task = new Task(doWork); task.ContinueWith(doMoreWork, TaskContinuationOptions. OnlyOnRanToCompletion); task.Start(); B. Task task = new Task(doWork); task.ContinueWith(doMoreWork, TaskContinuationOptions.NotOnFaulted); task.Start(); C. Task task = new Task(doWork); task.ContinueWith(doMoreWork, TaskContinuationOptions. OnlyOnCanceled); task.Start(); D. Task task = new Task(doWork); task.ContinueWith(doMoreWork, TaskContinuationOptions. NotOnRanToCompletion); task.Start(); Answer: D Q8. How can you suspend execution of the current thread until the specified task completes? A. By calling Suspend on the Task object B. By calling Sleep on the Task object C. By calling Wait on the Task object D. By calling Stop on the Task object Answer: C Q9. Consider the code snippet (Line numbers are only for reference) 1. Task task = Task.Run(()=>...); 2. task.start(); 3. You want to suspend execution of the current thread until the specified task completes. Which statement should you write at line 3? A. task.Wait(); B. Task.Complete(); C. Thread.Suspend(); D. Thread.Sleep(); Answer: A Q10. You have created two tasks Task task1=.... ; Task task2=... ; You want to suspend execution of the current thread until at one of the tasks completes. Which statement should you use? A. Task.Wait(task1,task2); B. Task.WaitAll(task1,task2); C. Task.WaitAny(task1,task2); 2 D. task1.ContinueWith (task2); Answer: C Q11. Which class do you use to parallelize some common programming constructs without requiring that you redesign an application? A. Task B. Thread C. ThreadPool D. Parallel Answer: D Q12. How do you perform loop iterations and statement sequences by using parallel tasks? A. Using Task class B. Using Parallel.For and Parallel.ForEach methods C. Using Thread class D. Using ThreadPool class Answer: B Q13. Which one you can use to wait for a Task to finish only in async method? A. Call the Run method on the Task object B. Call the Wait method on the Task object C. use async keyword D. use the await operator Answer: D 3 Microsoft Visual C# Step by Step Chapter 22: Operator overloading Q1. What is operator overloading? A. To define how built-in operators should behave for your own structures and classes B. To define new operators for your own structures and classes C. To disable certain behavior of existing operators D. To change precedence of operators Answer: A Q2. Which operator is right-associative? A. ++ B. % C. = D. && Answer: C Q3. Which one defines whether the operator evaluates from left to right or from right to left? A. Operator precedence B. Operator overloading C. Operator associativity D. None of the above Answer: C Q4. Which type of operator operates on just one operand? A. Unary operator B. Binary operator C. Trinary Operator D. None of the above Answer: A Q5. Which type of operator operates on two operands? A. Unary operator B. Binary operator C. Trinary Operator D. None of the above Answer: B Q6. Which of the following is a unary operator? A. + B. += C. ? D. ++ Answer: D Q7. Which operator you cannot overload? A. Plus (+) B. Increment (++) C. Equality (==) D. Dot (.) Answer: D Q8. Which one of the following operator constraints is not true? A. You cannot change the precedence and associativity of an operator. 1 B. You cannot change the multiplicity (the number of operands) of an operator. C. You cannot invent new operator symbols D. You cannot overload conversion operator Answer: D [You can overload implicit and explicit casting operator] Q9. Which of the following is not true while overloading operators? A. All operators must be public B. All operators must be static C. virtual, abstract, override, or sealed modifiers cannot be used D. overloaded operator cannot take any parameter Answer: A Q10. How do you define operator? A. public and static keywords, followed by the return type, followed by the operator keyword, followed by the operator symbol, followed by the appropriate parameters between parentheses B. public keyword, followed by the return type, followed by the operator symbol, followed by the appropriate parameters between parentheses C. public and static keywords, followed by the return type, followed by the operator symbol, followed by the appropriate parameters between parentheses D. public and static keywords, followed by the return type, followed by the operator symbol, followed by the appropriate parameters between parentheses, followed by the operator keyword Answer: A Q11. You are overloading operator for a class named Point. Which one is correct signature of the method for overloading + operator? A. public Point operator +(Point x, Point y) {...} B. public static Point +(Point x, Point y) {...} C. public static Point operator +(Point x, Point y) {...} D. public static Point +(Point x, Point y) {...} Answer: C Q12. Which operator must be overloaded as pairs? A. + and - B. * and / C. ++ and - - D. == and != Answer: D [== and!=, < and >, =, >= and

Use Quizgecko on...
Browser
Browser