1. What is the CLR?
The Common Language Runtime is the platform for .NET applications that allow developing application in any .NET languages (C#, Visual Basic etc.) and have those all run seamlessly on a single platform.
2. What are the four types of applications you can build in .NET?
Console, Windows, Web, and Web Services
3. What is the .NET Framework?
//The Framework specifies how .NET constructs intrinsic types, classes, interfaces, etc.
4. What is the FCL?
The Framework Class Library provides a very large suite of predefined classes that you can use in building application.
5. What does it mean to say that C# is a "safe" language?
This refers to "type safety". The ability of the compiler to ensure that the objects created is of the expected type.
6. What is a keyword?
Keywords are reserved for use by the language and cannot be used to identify objects or methods you create.
7. What is a namespace?
Namespaces are used to ensure that identifiers are unique across libraries of classes.
8. What does the compiler do?
The job of the compiler is to turn your source code into MSIL.
9. What is MSIL?
The Microsoft Intermediate Language is the native language for .NET and is compiled into an executable application by the JIT.
10. What is the JIT?
The Just in Time compiler turns your MSIL code into an application in memory.
11. What is the difference between a project and a solution?
A project results in the production of an executable or a library. Most solutions consist of a single project, but many consist of two or more.
12. How do you move windows in the IDE?
Click and drag on the title bar; use the indicators for placement.
13. What does the pushpin do on a window?
Toggles between lock in place, and hide as a tab.
14. What is the difference between pressing F5 and Ctrl-F5 from within Visual Studio 2005?
F5 indicates run with debugging; Ctrl-F5 indicates run without debugging.
15. What is the Clipboard Ring?
Allows you to store more than one item on the clipboard
16. How do you retrieve items from the clipboard ring?
Ctrl-Shift-V cycles through all the selections.
17. What is "Find Symbol" for?
Allows you to search for symbols (namespaces, classes, and interfaces) and their members (properties, methods, events, and variables)
18. What are bookmarks?
A tool for returning to a specific place in your code
19. What is IntelliSense?
An editing tool to help you find the right method and/or the correct parameters and much more
20. What is a code snippet?
A complete outline of a commonly used programming structure with replaceable items to speed development
21. What values can a bool type have?
True or False
22. What is the difference between an int and an Int32?
Int is the C# alias for the .NET Int32 type. They can be used interchangeably.
23. Which of the following code statements will compile?
int myInt = 25;
long myLong = myInt;
int newInt = myLong;
All except the last, this requires an explicit cast:
int newInt = (int) myLong;
24. What is the difference between an int and a uint?
A uint is an unsigned int and can hold only positive numbers, but it can hold a positive value twice as big as an int (4 million+ rather than 2 million+).
25. What is the difference between a float and a double?
A float takes four bytes and double takes eight bytes, and thus a double can represent much larger values with greater precision.
26. Explain definite assignment.
In C, if you wish to use a variable of any type (pass it as a parameter to a method), you must assign it a value.
27. Given the following declaration, how would you refer to the constant for LightJacketWeather and what would its value be?
Enum Temperatures
{
WickedCold = 0, FreezingPoint = 32, LightJacketWeather, SwimmingWeather = 72, BoilingPoint = 212,
}
You refer to the constant like this:
Temperatures.LightJacketWeather
Its value is 33.
28. What is an expression?
Any statement that evaluates to a value
29. What is the output of these operations?
4 * 8
(4 + 8) / (4 - 2)
4 + 8 / 4 – 2
The output of the operations is:
32
6
4
30. Set x = 25 and y = 5. What do these expressions evaluate to?
1. (x “= y) 2. (x “= y * 5) 3. (X == y) 4. (x = y) 5.(x “= y) && (y “= x)
The expressions evaluate to: 1) True 2) True 3) False 4) 5 5.)True
The fourth expression evaluates to 5, not to true. Thus, if you write: z = x = y; and y has the value 5, then the order of operations is that the value in y (5) is assigned to x, and the value of the expression x=y, which is 5, is assigned to z.
31. Describe the difference between the prefix and postfix operators.
The prefix operator increments the original value, and then assigns the new value to the result. The postfix operator assigns the original value to the result and then increments the original value.
32. Arrange these operators in order of precedence:
&
!=
?:
&&
++
The correct order of operations is:
++
%
!=
&&
?:
33. What statements are generally used for conditional branching?
If, else, switch.
34. True or false: an if statement's condition must evaluate to an expression.
False. In C#, an if statement's condition must evaluate to a Boolean expression
34. Why should you use braces when there is only one statement following the if?
The braces make maintenance easier. If you add a second statement later, you are less likely to create a logic error because it is obvious what "block" of statements the if refers to.
35. What kind of expression can be placed in a switch statement?
Either a numeric value or a string
36. True or false: you can never fall through in a switch statement.
False. If the statement has no body, then you can fall through. For example:
Case morning:
Case afternoon:
SomeAction ( );
Break;
37. Name two uses of goto.
Two uses of goto are:
• To go to a label in your code
• To go to a different case statement in a switch statement
38. What is the difference between while and do...while?
Do...while evaluates its condition at the end of the statement rather than at the beginning, and thus is guaranteed to run at least once.
39. What does the keyword continue do?
In a loop, it causes the remainder of the body of the loop to be skipped and the next iteration of the loop to begin immediately.
40. What are two ways to create a loop that never ends until you hit a break statement?
Two ways of creating an infinite loop are:
For (;;)
While (true)
41. How do you create a user-defined type in C#?
New (user-defined) types are most often created in C# with the keyword class.
42. What is the difference between a class and an object?
A class defines a new type; an object is an instance of that type.
43. Why should member fields be private?
Making your member fields private allows you to change how you store that data (as a member variable, in a database) without breaking your client's code.
44. What is encapsulation?
Encapsulation is the principle of keeping each class discreet and self-contained, so you can change the implementation of one class without affecting any other class.
45. What is specialization and how is it implemented in C#?
Specialization allows a new class to "inherit" many of the characteristics of an existing class, and to be used polymorphically with that class. Specialization is implemented in C# through inheritance.
46. What is polymorphism?
Polymorphism is the ability to treat derived classes as if they were all instances of their base class, yet have each derived class specialize its own implementation of the base class's methods.
47. What is the difference between is-a and has-a relationship?
The is-a relationship is established through inheritance. The has-a relationship is implemented through aggregation (making one type a member variable of another type).
48. What are access modifiers?
Access modifiers indicate which class' methods have access to a given field, property or method of a class. Public members are available to methods of any class; private members are available only to methods of instances of the same class.
49. Describe the differences between state, capabilities, and responsibilities
State is the current conditions and values of an object, and is implemented with properties and member variables. Capabilities are what the object can do, exposed through public methods. Responsibilities are the promises a well-designed class makes to the clients of that class.
50. What is a use-case scenario?
A use-case scenario is a tool for the analysis of a problem. In a use-case scenario, you walk through the details of how your product will be used by one user to accomplish one task, noting which classes interact and what their responsibilities are.
51. What is the difference between a class and an object?
A class defines a new type; an object is a single instance of that type.
52. Where is reference types created?
Instances of classes are reference types and are created on the heap.
53. Where is value types created?
Intrinsic types (such as integers) and structs are value types and are created on the stack.
54. What does the keyword private do?
Access is limited to methods of the defining class.
55. What does the keyword public do?
Access is available to methods in any class.
56. What method is called when you create an object?
The class's constructor is called.
57. What is a default constructor?
A default constructor is a constructor that takes no parameters. If you do not create any constructor at all for your class, a default constructor is implicitly created.
58. What types can a constructor return?
None. A constructor is not defined to return a type, and is not marked void.
59. How do you initialize the value of a member variable in a class?
Either in the constructor, using assignment, or when the member variable is created:
Private Int myVariable = 88;
Technically, only the latter is truly initialization; assigning it in the constructor is not as efficient.
60. What does the keyword this refers to?
This refers to the object itself, the current instance of the class.
61. What is the difference between a static method and an instance method?
A static method has no this reference. It does not belong to an instance; it belongs to the class and can only call other static methods. You access a static method through the name of the class:
Dog myDog = new Dog ( );
myDog.InstanceMethod ( );
Dog.StaticMethod ( );
Of course, from within any method (including static methods), you can instantiate a class, and then call methods on that instance.
You can even instantiate an instance of your own class, and then call any non-static method of that object, as we did with [static] Main( ) calling [non-static] Test( ).
62. What does the using statement do?
The using statement automatically calls the dispose method on the object once the statement completes.
63. What is method overloading and how must the overloaded methods differ?
Method overloading allows the author of the class to create a method with varying (number and/or type of) parameters, rather than having to have many methods with similar but different names.
64. What is the signature of a method?
The signature of a method is its name and its parameter list.
65. What are properties?
Properties are public accessors to your encapsulated data. Properties appear to the class creator as methods, but to the class's clients as fields.
66. How do you create a read-only property?
Do not implement the set part of the property. No special notation is required.
67. How do you retrieve more than one return value from a method?
By passing in parameters by reference and getting the results back in those parameters.
68. Where must you use the keyword ref?
If you want to pass a value object (variable) by reference, you can use the keyword ref in the call to the method and in the declaration of the method.
69. What is the keyword out used for?
If you want to pass a value object by reference, but do not want to initialize it, you must use the keyword out in the call to the method and in the declaration of the method.
70. What is the easiest way to set a breakpoint?
Go to the line where you want execution to stop, and click in the margin. A red dot will appear on the line.
71. How do you step over or into a method?
Pressing F10 steps over a method; F11 steps into the method.
72. How can you disable breakpoints, and set conditions on breakpoints?
Right-click on the line and choose breakpoints and then disable breakpoint, or right-click on the breakpoint and choose disable.
73. What is the difference between the Locals window and the Autos window?
The Locals window shows all the variables that are in scope. The Autos window shows variables used in the current and previous statement.
74. What is the easiest way to set a watch on a variable?
Either right-click on the variable and choose "Add to Watch window" or just click and drag the variable directly onto the Watch window.
75. How do you open a QuickWatch window?
Right-click on the variable and choose "QuickWatch," or select Debug QuickWatch.
76. What does the call stack show and why is it useful?
The call stack shows which method called the current method, and which method called that method, etc. This allows you to determine the exact path your code followed to bring you to the current method.
77. What is the index of the seventh member of an array?
6. Arrays always begin with index (or offset) zero.
78. Are arrays type-safe?
Yes. Every array declares the type of objects it will hold. You can undermine the type-safety by creating an array of objects (which will hold anything, because everything derives from objects), but that is not advised.
79. Are arrays reference or value types? And where are they created?
Arrays are reference types and created on the heap.
80. Where are the elements of the array created?
If the elements of the array are of value types, they are created in the allocated memory for the array; otherwise, they are created elsewhere on the heap and a reference is stored in the array.
81. What are the two ways to initialize an array of three values?
You can explicitly call new or just imply the size of the array. For example, if you have three employee objects named Moe, Larry, and Corley:
Employee [] myEmpArray = new Employee [3] = {Moe, Larry, Corley};
Or: Employee [] myEmpArray = {Moe, Larry, Corley};
82. What does the params keyword do?
Allows you to pass in an indefinite number of parameters, all of the same type, which will be treated as an array. You can, if you wish, also pass in an array.
83. What are the two types of multidimensional arrays and what is the difference between them?
A rectangular array is a multidimensional array; a jagged array is an array of arrays.
84. What is the relationship between specialization and generalization?
This relationship is reciprocal: if you have three types with similar functionality, you can refactor that similarity out of the three types into a generalized type. At the same time, each of the three types are now specialized forms of the more generalized type.
Inheritance is also implicitly hierarchical: you can imagine a tree with the most generalized type at the top and each level of specialization descending from levels above. A generalized type may have many specializations, but each specialized type may have only one generalization.
85. How is specialization implemented in C#?
Through inheritance
86. What is the syntax for inheritance in C#?
Class “identifier” : “base class”
87. How do you implement polymorphism?
Create a virtual method in the base class, and then override it in the derived class.
88. What are the two meanings of the keyword new?
The more usual meaning is to allocate memory on the heap. The special meaning in inheritance is that you are not overriding a base method; you are creating a new method that intentionally hides and replaces the base class method.
89. How do you call a base class constructor from a derived class?
After the parameter list, but before the opening brace, put a colon followed by the keyword base and two parentheses. Pass the parameters for the base class constructor within the parentheses.
90. What is the difference between public, protected, and private?
A member of class A is visible to class B if it is marked public or if it is marked protected and class B derives directly or indirectly from A. If the member is marked private in A, it is always invisible to class B.
91. What is an abstract method?
An abstract method has no implementation in the base class, but must be overridden and implemented in any derived class that does not itself want to be abstract. Any class with an abstract method (even if inherited) is itself abstract and may not be instantiated.
92. What is a sealed class?
A sealed class is one that the compiler will not let you derive from. Classes are marked sealed when the designer of the class does not want anyone to create a derived version.
93. What is the base class of Int32?
Object (which is the ultimate base class (root) of all types in C#)
94. What is the base class of any class you create if you do not otherwise indicate a base class?
Object.
95. What is boxing?
If you use a value type where an Object is expected, the value type will be automatically and invisibly wrapped in an Object and will take on reference characteristics.
96. What is unboxing?
When you return a boxed type back to its original type, you must unbox it and explicitly cast it.
97. What is operator overloading?
The process of writing methods for your class that allows clients of your class to interact with your class using standard operators (+, ==).
98. Are operators implemented as properties, static methods, or instance methods?
Static methods
99. How does the compiler translate?
Fraction f3 = f2 + f1;
Assuming that f2 and f1 are Fraction objects and you have overloaded the + operator for the Fraction class?
Call to: public static Fraction operator+ (f2, f1)
100. What should you also do if you overload the == operator?
Overload the Equals ( ) method.
101. What is the difference between implicit and explicit conversion?
Use implicit conversion when you know the conversion will succeed without the risk of losing information. Use explicit conversion if information might be lost.
102. What is the difference between an interface and a class that implements an interface?
The interface defines the methods, properties, etc. that the implementing class must provide. The implementing class provides these members and, optionally, additional members.
103. What is the difference between an interface and an abstract base class?
Every class has exactly one base class, but may implement zero, one, or more interfaces. An abstract base class serves as the base to a derived class that must implement all its abstract methods or that derived class is also abstract.
104. How do you indicate that class MyClass derives from class MyBase and implements the interfaces ISuppose and IDo?
Class MyClass: MyBase, ISuppose, IDo {}
Note that the base class must come first after the colon.
105. What two operators can tell you if an object's class implements an interface?
The is and the as operator.
106. What is the difference between is and as operators?
Is returns false if the interface is not implemented; as returns null. Using the as operator can be more efficient.
107. What does it mean to "extend" an interface?
Extending an interface is very much like deriving a class. The new interface inherits all the members of the parent interface, and can also include additional methods.
108. What is the syntax for extending an interface?
ExtendedInterface: OriginalInterface
For example, read:
ILoggedCompressible: Incompressible
As "ILogged Compressible extends ICompressible"
109. What does it mean to override an interface implementation?
The class implementing a method of the interface can mark that method virtual, and the implementation of the method can be overridden in derived classes.
110. What is explicit interface implementation and why would you use it?
Explicit interface implementation identifies the member of the interface by naming the interface itself (e.g., IStorable.Write ( )). This is done to differentiate implementation methods when there might otherwise be an ambiguity, such as when implementing more than one interfaces that have methods with the same signature.
111. What is the convention for naming an indexer?
Indexers are unnamed. You use this keyword to create an indexer:
Public string this [int index]
112. What types can be used in an indexer to index a collection?
Any type can be used, although it's most common to use integers.
113. What are the preconditions for calling Sort ( ) on an array?
The elements of the array must implement IComparable.
114. What is the purpose of generics?
Generics allow you to create type-safe collections without specifying the type the collection will hold when you create the collection.
115. What is the IEnumerable”T” interface?
It allows your collection to support a foreach loop.
116. What is the principal difference between a List”T” and an array?
The size of an array is fixed when you create it. A List”T” expands dynamically when you add more elements.
117. What is the difference between a List, a Stack, a Queue, and a Dictionary?
A List is like an expandable array. A Stack is a "Last In, First Out" collection, a Queue is a "First In, First Out" collection, and a Dictionary is a collection of key/value pairs where you can retrieve the value given a key.
118. What is the difference between string and String (lower- and uppercase)?
string (lowercase) is the C# keyword that maps to the .NET Framework String class. They may be used interchangeably.
119. Some of the interfaces implemented by the string are: IComparable, ICloneable, IConvertible and IEnumerable. What do these guarantees to you as a client of the String class?
IComparable: Guarantees that strings can be sorted
ICloneable: Guarantees that you can call the Clone method on a string object and get back a new duplicate string
IConvertible: Allows strings to be converted to other types (such as integers)
IEnumerable: Guarantees that strings can be iterated over in foreach loops
120. What is a string literal?
A quoted string, provided by the programmer, such as "Hello"
121. What is the purpose of escape characters? Give two examples.
An escape character embedded in a string indicates that the character or punctuation that follows is to be treated as an instruction rather than as part of the string. \n indicates a new line. \" indicates that the quote symbol is in the string, not terminating it.
122. What are verbatim strings?
Verbatim strings are taken "as is" and thus do not require escape characters. Where \\ would indicate a single backslash in a normal string, in a verbatim string, it indicates two backslashes.
123. What does it mean that strings are immutable?
Strings cannot be changed. When you appear to change a string, what actually happens is that a new string is created and the old string is destroyed by the garbage collector if it is no longer referenced.
124. What does it mean that the String class is sealed?
It is not possible to derive from the String class (or any other sealed class).
125. What are the two ways to concatenate strings?
You can call the Concat method of the String class, but it is more common to use the overloaded + operator.
126. What does Split ( ) do?
Given an array of delimiters, Split ( ) returns the substrings of the original string.
127. what is the StringBuilder class, why is it used, and how do you create a string with one?
StringBuilder objects are mutable. When the StringBuilder has the complete set of characters you want, you call ToString ( ) to get back a string object.
128. What are regular expressions?
Regular expressions constitute a language for identifying and manipulating strings using both literal and metacharacters.
129. What is an exception?
An exception is an object (derived from System.Exception) that contains information about a problematic event. The framework supports throwing exceptions to stop processing and catching events to handle the problem and resume processing.
130. What does the framework do if no exception handler is found in the method that throws an event?
The stack is unwound until a handler is found, or else the exception is handled by the CLR, which terminates the program.
131. How do you create a handler?
You create a try/catch block; the catch part is the exception handler.
132. What is the syntax for throwing a new ArgumentNull exception?
The syntax is:
Throw new Sytem.ArgumentNullException ( )
133. How do you write code to handle various exceptions differently?
You can write multiple exception handlers to handle different exceptions; the first handler that catches the thrown exception will prevent further handling. Beware of inheritance complications in the ordering of your handlers.
134. What is the finally statement?
If you have code that must run whether or not an exception is thrown (to close a file, for example), place that code in the finally block. You must have a try for the finally, but a catch is optional.
135. Define an event to signal that the phone has rung.
The following is the standard way to define a delegate:
Public delegate void PhoneRangHandler
(Object sender, EventArgs e);
Public event PhoneRangHandler PhoneRang;
136. Are delegates value types or reference types?
Reference types
137. What is the purpose of a delegate?
To decouple the method(s) called from the calling code. It allows the designer of an object to define the delegate, and the user of the object to define which method will be called when the delegate is invoked.
138. How do you instantiate a delegate, such as the OnPhoneRings delegate described in the first question?
You instantiate a delegate like this:
OnPhoneRings myDelegate = new OnPhoneRings (myMethod);
139. Give an example of how you might call the delegated method through the delegate.
Here is how to call a delegated method:
OnPhoneRings (object this, new EventArgs ( ));
140. What is multicasting?
The ability for more than one method to be called through a single delegate
141. What does the event keyword do?
Limits the use of the delegate in the following ways:
• You can only add a method using +=.
• You can only remove a method using -=.
• The delegate can only be invoked by the class that defines it.
142. If you want to pass information into the method that is called through the event, how do you do so?
Define the delegate to take, as its second parameter, an object of a type derived from EventArgs. Pass the information through properties of that object.
143. What properties or methods does System.EventArgs have?
None
144. How can you create delegated methods anonymously?
Rather than creating a method that matches the delegate's signature and then assigning the name of that method to the delegate, you can directly assign an unnamed delegate method by providing the implementation in line with the assignment.
145. How can you set the properties of a control?
Click on the control on the form, and then set the properties in the Properties window.
146. How do you make a button respond to being clicked?
Implement an event handler.
147. Name two ways to create an event handler.
The two ways to create an event handler are as follows:
• Go to the Properties window, click on the lightning button to open the events, then fill in a name or double-click next to the event to let Visual Studio 2005 create the name.
• Double-click on the control to create the default handler with a name provided by Visual Studio 2005.
148. What is recursion?
A method calling itself (such as calling Method A ( ) from within the body of Method A ( ))
149. What are the XML documentation comments?
XML documentation comments are preceded with three slashes, and are used to generate XML documents that can be used to document the application.
150. How do you see the code created by Visual Studio 2005 to create and initialize the controls on the form?
Click the ShowAllFiles button on the Solution Explorer and examine the “FormName”.Designer file.
151. What are the two most significant and commonly used namespaces for ASP.NET?
System.Web and System.Web.UI.Page
152. Where does ASP.NET code run?
On the server (though occasionally some Web Controls will write script to run on the client)
153. How do you ensure that a radio button selection or checkbox selection will be immediately posted to the server?
Making a non-postback event into a postback event is accomplished simply by setting the AutoPostBack property to true.
154. What is view state?
View state is the ability of ASP.NET pages to store the state of their controls during a post-back; the net effect is that the programmer does not have to write code to maintain the state of controls when a page is posted back to the server.
155. If you rename your class, all references to the class name will be updated, except that you will be warned that the reference in "markup" will not be changed. What does this mean?
You must update the Page directive to ensure that the Inherits property is set to the new class name.
156. If you click F5 to run your program, you may see a dialog box saying that debugging is not enabled. What should you do?
Click "Add a new web.config file with debugging enabled," and Visual Studio 2005 will create a web.config file for you, or alternatively, you can create the file yourself (by hand) and then add it to the project.
157. What are the three ways to add Server Controls to your form?
The three ways are as follows:
• Drag them from the toolbox.
• Write the code in the HTML markup window.
• Add them programmatically.
158. What property must every Server Control have?
Every Server Control must have this property:
Runat="Server"
159. Which control is used to enable data binding from a database to controls on a Web Form?
The DataSource control
160. When you create an “ASP: RadioButtonList” with “ASP: RadioButtonList” controls in it, what is sent to the browser?
A series of “input” elements of type "radio" with associated “label” controls all contained within a “table”.
161. How do you ensure that an action you want to take happens only the first time the page is shown, and does not happen if the user clicks a button or takes another action to post the page back to the server for processing?
Test for the IsPostBack property of the page. If true, the page has been posted back.
5) Can you mark a method as protected in an interface
The Common Language Runtime is the platform for .NET applications that allow developing application in any .NET languages (C#, Visual Basic etc.) and have those all run seamlessly on a single platform.
2. What are the four types of applications you can build in .NET?
Console, Windows, Web, and Web Services
3. What is the .NET Framework?
//The Framework specifies how .NET constructs intrinsic types, classes, interfaces, etc.
4. What is the FCL?
The Framework Class Library provides a very large suite of predefined classes that you can use in building application.
5. What does it mean to say that C# is a "safe" language?
This refers to "type safety". The ability of the compiler to ensure that the objects created is of the expected type.
6. What is a keyword?
Keywords are reserved for use by the language and cannot be used to identify objects or methods you create.
7. What is a namespace?
Namespaces are used to ensure that identifiers are unique across libraries of classes.
8. What does the compiler do?
The job of the compiler is to turn your source code into MSIL.
9. What is MSIL?
The Microsoft Intermediate Language is the native language for .NET and is compiled into an executable application by the JIT.
10. What is the JIT?
The Just in Time compiler turns your MSIL code into an application in memory.
11. What is the difference between a project and a solution?
A project results in the production of an executable or a library. Most solutions consist of a single project, but many consist of two or more.
12. How do you move windows in the IDE?
Click and drag on the title bar; use the indicators for placement.
13. What does the pushpin do on a window?
Toggles between lock in place, and hide as a tab.
14. What is the difference between pressing F5 and Ctrl-F5 from within Visual Studio 2005?
F5 indicates run with debugging; Ctrl-F5 indicates run without debugging.
15. What is the Clipboard Ring?
Allows you to store more than one item on the clipboard
16. How do you retrieve items from the clipboard ring?
Ctrl-Shift-V cycles through all the selections.
17. What is "Find Symbol" for?
Allows you to search for symbols (namespaces, classes, and interfaces) and their members (properties, methods, events, and variables)
18. What are bookmarks?
A tool for returning to a specific place in your code
19. What is IntelliSense?
An editing tool to help you find the right method and/or the correct parameters and much more
20. What is a code snippet?
A complete outline of a commonly used programming structure with replaceable items to speed development
21. What values can a bool type have?
True or False
22. What is the difference between an int and an Int32?
Int is the C# alias for the .NET Int32 type. They can be used interchangeably.
23. Which of the following code statements will compile?
int myInt = 25;
long myLong = myInt;
int newInt = myLong;
All except the last, this requires an explicit cast:
int newInt = (int) myLong;
24. What is the difference between an int and a uint?
A uint is an unsigned int and can hold only positive numbers, but it can hold a positive value twice as big as an int (4 million+ rather than 2 million+).
25. What is the difference between a float and a double?
A float takes four bytes and double takes eight bytes, and thus a double can represent much larger values with greater precision.
26. Explain definite assignment.
In C, if you wish to use a variable of any type (pass it as a parameter to a method), you must assign it a value.
27. Given the following declaration, how would you refer to the constant for LightJacketWeather and what would its value be?
Enum Temperatures
{
WickedCold = 0, FreezingPoint = 32, LightJacketWeather, SwimmingWeather = 72, BoilingPoint = 212,
}
You refer to the constant like this:
Temperatures.LightJacketWeather
Its value is 33.
28. What is an expression?
Any statement that evaluates to a value
29. What is the output of these operations?
4 * 8
(4 + 8) / (4 - 2)
4 + 8 / 4 – 2
The output of the operations is:
32
6
4
30. Set x = 25 and y = 5. What do these expressions evaluate to?
1. (x “= y) 2. (x “= y * 5) 3. (X == y) 4. (x = y) 5.(x “= y) && (y “= x)
The expressions evaluate to: 1) True 2) True 3) False 4) 5 5.)True
The fourth expression evaluates to 5, not to true. Thus, if you write: z = x = y; and y has the value 5, then the order of operations is that the value in y (5) is assigned to x, and the value of the expression x=y, which is 5, is assigned to z.
31. Describe the difference between the prefix and postfix operators.
The prefix operator increments the original value, and then assigns the new value to the result. The postfix operator assigns the original value to the result and then increments the original value.
32. Arrange these operators in order of precedence:
&
!=
?:
&&
++
The correct order of operations is:
++
%
!=
&&
?:
33. What statements are generally used for conditional branching?
If, else, switch.
34. True or false: an if statement's condition must evaluate to an expression.
False. In C#, an if statement's condition must evaluate to a Boolean expression
34. Why should you use braces when there is only one statement following the if?
The braces make maintenance easier. If you add a second statement later, you are less likely to create a logic error because it is obvious what "block" of statements the if refers to.
35. What kind of expression can be placed in a switch statement?
Either a numeric value or a string
36. True or false: you can never fall through in a switch statement.
False. If the statement has no body, then you can fall through. For example:
Case morning:
Case afternoon:
SomeAction ( );
Break;
37. Name two uses of goto.
Two uses of goto are:
• To go to a label in your code
• To go to a different case statement in a switch statement
38. What is the difference between while and do...while?
Do...while evaluates its condition at the end of the statement rather than at the beginning, and thus is guaranteed to run at least once.
39. What does the keyword continue do?
In a loop, it causes the remainder of the body of the loop to be skipped and the next iteration of the loop to begin immediately.
40. What are two ways to create a loop that never ends until you hit a break statement?
Two ways of creating an infinite loop are:
For (;;)
While (true)
41. How do you create a user-defined type in C#?
New (user-defined) types are most often created in C# with the keyword class.
42. What is the difference between a class and an object?
A class defines a new type; an object is an instance of that type.
43. Why should member fields be private?
Making your member fields private allows you to change how you store that data (as a member variable, in a database) without breaking your client's code.
44. What is encapsulation?
Encapsulation is the principle of keeping each class discreet and self-contained, so you can change the implementation of one class without affecting any other class.
45. What is specialization and how is it implemented in C#?
Specialization allows a new class to "inherit" many of the characteristics of an existing class, and to be used polymorphically with that class. Specialization is implemented in C# through inheritance.
46. What is polymorphism?
Polymorphism is the ability to treat derived classes as if they were all instances of their base class, yet have each derived class specialize its own implementation of the base class's methods.
47. What is the difference between is-a and has-a relationship?
The is-a relationship is established through inheritance. The has-a relationship is implemented through aggregation (making one type a member variable of another type).
48. What are access modifiers?
Access modifiers indicate which class' methods have access to a given field, property or method of a class. Public members are available to methods of any class; private members are available only to methods of instances of the same class.
49. Describe the differences between state, capabilities, and responsibilities
State is the current conditions and values of an object, and is implemented with properties and member variables. Capabilities are what the object can do, exposed through public methods. Responsibilities are the promises a well-designed class makes to the clients of that class.
50. What is a use-case scenario?
A use-case scenario is a tool for the analysis of a problem. In a use-case scenario, you walk through the details of how your product will be used by one user to accomplish one task, noting which classes interact and what their responsibilities are.
51. What is the difference between a class and an object?
A class defines a new type; an object is a single instance of that type.
52. Where is reference types created?
Instances of classes are reference types and are created on the heap.
53. Where is value types created?
Intrinsic types (such as integers) and structs are value types and are created on the stack.
54. What does the keyword private do?
Access is limited to methods of the defining class.
55. What does the keyword public do?
Access is available to methods in any class.
56. What method is called when you create an object?
The class's constructor is called.
57. What is a default constructor?
A default constructor is a constructor that takes no parameters. If you do not create any constructor at all for your class, a default constructor is implicitly created.
58. What types can a constructor return?
None. A constructor is not defined to return a type, and is not marked void.
59. How do you initialize the value of a member variable in a class?
Either in the constructor, using assignment, or when the member variable is created:
Private Int myVariable = 88;
Technically, only the latter is truly initialization; assigning it in the constructor is not as efficient.
60. What does the keyword this refers to?
This refers to the object itself, the current instance of the class.
61. What is the difference between a static method and an instance method?
A static method has no this reference. It does not belong to an instance; it belongs to the class and can only call other static methods. You access a static method through the name of the class:
Dog myDog = new Dog ( );
myDog.InstanceMethod ( );
Dog.StaticMethod ( );
Of course, from within any method (including static methods), you can instantiate a class, and then call methods on that instance.
You can even instantiate an instance of your own class, and then call any non-static method of that object, as we did with [static] Main( ) calling [non-static] Test( ).
62. What does the using statement do?
The using statement automatically calls the dispose method on the object once the statement completes.
63. What is method overloading and how must the overloaded methods differ?
Method overloading allows the author of the class to create a method with varying (number and/or type of) parameters, rather than having to have many methods with similar but different names.
64. What is the signature of a method?
The signature of a method is its name and its parameter list.
65. What are properties?
Properties are public accessors to your encapsulated data. Properties appear to the class creator as methods, but to the class's clients as fields.
66. How do you create a read-only property?
Do not implement the set part of the property. No special notation is required.
67. How do you retrieve more than one return value from a method?
By passing in parameters by reference and getting the results back in those parameters.
68. Where must you use the keyword ref?
If you want to pass a value object (variable) by reference, you can use the keyword ref in the call to the method and in the declaration of the method.
69. What is the keyword out used for?
If you want to pass a value object by reference, but do not want to initialize it, you must use the keyword out in the call to the method and in the declaration of the method.
70. What is the easiest way to set a breakpoint?
Go to the line where you want execution to stop, and click in the margin. A red dot will appear on the line.
71. How do you step over or into a method?
Pressing F10 steps over a method; F11 steps into the method.
72. How can you disable breakpoints, and set conditions on breakpoints?
Right-click on the line and choose breakpoints and then disable breakpoint, or right-click on the breakpoint and choose disable.
73. What is the difference between the Locals window and the Autos window?
The Locals window shows all the variables that are in scope. The Autos window shows variables used in the current and previous statement.
74. What is the easiest way to set a watch on a variable?
Either right-click on the variable and choose "Add to Watch window" or just click and drag the variable directly onto the Watch window.
75. How do you open a QuickWatch window?
Right-click on the variable and choose "QuickWatch," or select Debug QuickWatch.
76. What does the call stack show and why is it useful?
The call stack shows which method called the current method, and which method called that method, etc. This allows you to determine the exact path your code followed to bring you to the current method.
77. What is the index of the seventh member of an array?
6. Arrays always begin with index (or offset) zero.
78. Are arrays type-safe?
Yes. Every array declares the type of objects it will hold. You can undermine the type-safety by creating an array of objects (which will hold anything, because everything derives from objects), but that is not advised.
79. Are arrays reference or value types? And where are they created?
Arrays are reference types and created on the heap.
80. Where are the elements of the array created?
If the elements of the array are of value types, they are created in the allocated memory for the array; otherwise, they are created elsewhere on the heap and a reference is stored in the array.
81. What are the two ways to initialize an array of three values?
You can explicitly call new or just imply the size of the array. For example, if you have three employee objects named Moe, Larry, and Corley:
Employee [] myEmpArray = new Employee [3] = {Moe, Larry, Corley};
Or: Employee [] myEmpArray = {Moe, Larry, Corley};
82. What does the params keyword do?
Allows you to pass in an indefinite number of parameters, all of the same type, which will be treated as an array. You can, if you wish, also pass in an array.
83. What are the two types of multidimensional arrays and what is the difference between them?
A rectangular array is a multidimensional array; a jagged array is an array of arrays.
84. What is the relationship between specialization and generalization?
This relationship is reciprocal: if you have three types with similar functionality, you can refactor that similarity out of the three types into a generalized type. At the same time, each of the three types are now specialized forms of the more generalized type.
Inheritance is also implicitly hierarchical: you can imagine a tree with the most generalized type at the top and each level of specialization descending from levels above. A generalized type may have many specializations, but each specialized type may have only one generalization.
85. How is specialization implemented in C#?
Through inheritance
86. What is the syntax for inheritance in C#?
Class “identifier” : “base class”
87. How do you implement polymorphism?
Create a virtual method in the base class, and then override it in the derived class.
88. What are the two meanings of the keyword new?
The more usual meaning is to allocate memory on the heap. The special meaning in inheritance is that you are not overriding a base method; you are creating a new method that intentionally hides and replaces the base class method.
89. How do you call a base class constructor from a derived class?
After the parameter list, but before the opening brace, put a colon followed by the keyword base and two parentheses. Pass the parameters for the base class constructor within the parentheses.
90. What is the difference between public, protected, and private?
A member of class A is visible to class B if it is marked public or if it is marked protected and class B derives directly or indirectly from A. If the member is marked private in A, it is always invisible to class B.
91. What is an abstract method?
An abstract method has no implementation in the base class, but must be overridden and implemented in any derived class that does not itself want to be abstract. Any class with an abstract method (even if inherited) is itself abstract and may not be instantiated.
92. What is a sealed class?
A sealed class is one that the compiler will not let you derive from. Classes are marked sealed when the designer of the class does not want anyone to create a derived version.
93. What is the base class of Int32?
Object (which is the ultimate base class (root) of all types in C#)
94. What is the base class of any class you create if you do not otherwise indicate a base class?
Object.
95. What is boxing?
If you use a value type where an Object is expected, the value type will be automatically and invisibly wrapped in an Object and will take on reference characteristics.
96. What is unboxing?
When you return a boxed type back to its original type, you must unbox it and explicitly cast it.
97. What is operator overloading?
The process of writing methods for your class that allows clients of your class to interact with your class using standard operators (+, ==).
98. Are operators implemented as properties, static methods, or instance methods?
Static methods
99. How does the compiler translate?
Fraction f3 = f2 + f1;
Assuming that f2 and f1 are Fraction objects and you have overloaded the + operator for the Fraction class?
Call to: public static Fraction operator+ (f2, f1)
100. What should you also do if you overload the == operator?
Overload the Equals ( ) method.
101. What is the difference between implicit and explicit conversion?
Use implicit conversion when you know the conversion will succeed without the risk of losing information. Use explicit conversion if information might be lost.
102. What is the difference between an interface and a class that implements an interface?
The interface defines the methods, properties, etc. that the implementing class must provide. The implementing class provides these members and, optionally, additional members.
103. What is the difference between an interface and an abstract base class?
Every class has exactly one base class, but may implement zero, one, or more interfaces. An abstract base class serves as the base to a derived class that must implement all its abstract methods or that derived class is also abstract.
104. How do you indicate that class MyClass derives from class MyBase and implements the interfaces ISuppose and IDo?
Class MyClass: MyBase, ISuppose, IDo {}
Note that the base class must come first after the colon.
105. What two operators can tell you if an object's class implements an interface?
The is and the as operator.
106. What is the difference between is and as operators?
Is returns false if the interface is not implemented; as returns null. Using the as operator can be more efficient.
107. What does it mean to "extend" an interface?
Extending an interface is very much like deriving a class. The new interface inherits all the members of the parent interface, and can also include additional methods.
108. What is the syntax for extending an interface?
ExtendedInterface: OriginalInterface
For example, read:
ILoggedCompressible: Incompressible
As "ILogged Compressible extends ICompressible"
109. What does it mean to override an interface implementation?
The class implementing a method of the interface can mark that method virtual, and the implementation of the method can be overridden in derived classes.
110. What is explicit interface implementation and why would you use it?
Explicit interface implementation identifies the member of the interface by naming the interface itself (e.g., IStorable.Write ( )). This is done to differentiate implementation methods when there might otherwise be an ambiguity, such as when implementing more than one interfaces that have methods with the same signature.
111. What is the convention for naming an indexer?
Indexers are unnamed. You use this keyword to create an indexer:
Public string this [int index]
112. What types can be used in an indexer to index a collection?
Any type can be used, although it's most common to use integers.
113. What are the preconditions for calling Sort ( ) on an array?
The elements of the array must implement IComparable.
114. What is the purpose of generics?
Generics allow you to create type-safe collections without specifying the type the collection will hold when you create the collection.
115. What is the IEnumerable”T” interface?
It allows your collection to support a foreach loop.
116. What is the principal difference between a List”T” and an array?
The size of an array is fixed when you create it. A List”T” expands dynamically when you add more elements.
117. What is the difference between a List, a Stack, a Queue, and a Dictionary?
A List is like an expandable array. A Stack is a "Last In, First Out" collection, a Queue is a "First In, First Out" collection, and a Dictionary is a collection of key/value pairs where you can retrieve the value given a key.
118. What is the difference between string and String (lower- and uppercase)?
string (lowercase) is the C# keyword that maps to the .NET Framework String class. They may be used interchangeably.
119. Some of the interfaces implemented by the string are: IComparable, ICloneable, IConvertible and IEnumerable. What do these guarantees to you as a client of the String class?
IComparable: Guarantees that strings can be sorted
ICloneable: Guarantees that you can call the Clone method on a string object and get back a new duplicate string
IConvertible: Allows strings to be converted to other types (such as integers)
IEnumerable: Guarantees that strings can be iterated over in foreach loops
120. What is a string literal?
A quoted string, provided by the programmer, such as "Hello"
121. What is the purpose of escape characters? Give two examples.
An escape character embedded in a string indicates that the character or punctuation that follows is to be treated as an instruction rather than as part of the string. \n indicates a new line. \" indicates that the quote symbol is in the string, not terminating it.
122. What are verbatim strings?
Verbatim strings are taken "as is" and thus do not require escape characters. Where \\ would indicate a single backslash in a normal string, in a verbatim string, it indicates two backslashes.
123. What does it mean that strings are immutable?
Strings cannot be changed. When you appear to change a string, what actually happens is that a new string is created and the old string is destroyed by the garbage collector if it is no longer referenced.
124. What does it mean that the String class is sealed?
It is not possible to derive from the String class (or any other sealed class).
125. What are the two ways to concatenate strings?
You can call the Concat method of the String class, but it is more common to use the overloaded + operator.
126. What does Split ( ) do?
Given an array of delimiters, Split ( ) returns the substrings of the original string.
127. what is the StringBuilder class, why is it used, and how do you create a string with one?
StringBuilder objects are mutable. When the StringBuilder has the complete set of characters you want, you call ToString ( ) to get back a string object.
128. What are regular expressions?
Regular expressions constitute a language for identifying and manipulating strings using both literal and metacharacters.
129. What is an exception?
An exception is an object (derived from System.Exception) that contains information about a problematic event. The framework supports throwing exceptions to stop processing and catching events to handle the problem and resume processing.
130. What does the framework do if no exception handler is found in the method that throws an event?
The stack is unwound until a handler is found, or else the exception is handled by the CLR, which terminates the program.
131. How do you create a handler?
You create a try/catch block; the catch part is the exception handler.
132. What is the syntax for throwing a new ArgumentNull exception?
The syntax is:
Throw new Sytem.ArgumentNullException ( )
133. How do you write code to handle various exceptions differently?
You can write multiple exception handlers to handle different exceptions; the first handler that catches the thrown exception will prevent further handling. Beware of inheritance complications in the ordering of your handlers.
134. What is the finally statement?
If you have code that must run whether or not an exception is thrown (to close a file, for example), place that code in the finally block. You must have a try for the finally, but a catch is optional.
135. Define an event to signal that the phone has rung.
The following is the standard way to define a delegate:
Public delegate void PhoneRangHandler
(Object sender, EventArgs e);
Public event PhoneRangHandler PhoneRang;
136. Are delegates value types or reference types?
Reference types
137. What is the purpose of a delegate?
To decouple the method(s) called from the calling code. It allows the designer of an object to define the delegate, and the user of the object to define which method will be called when the delegate is invoked.
138. How do you instantiate a delegate, such as the OnPhoneRings delegate described in the first question?
You instantiate a delegate like this:
OnPhoneRings myDelegate = new OnPhoneRings (myMethod);
139. Give an example of how you might call the delegated method through the delegate.
Here is how to call a delegated method:
OnPhoneRings (object this, new EventArgs ( ));
140. What is multicasting?
The ability for more than one method to be called through a single delegate
141. What does the event keyword do?
Limits the use of the delegate in the following ways:
• You can only add a method using +=.
• You can only remove a method using -=.
• The delegate can only be invoked by the class that defines it.
142. If you want to pass information into the method that is called through the event, how do you do so?
Define the delegate to take, as its second parameter, an object of a type derived from EventArgs. Pass the information through properties of that object.
143. What properties or methods does System.EventArgs have?
None
144. How can you create delegated methods anonymously?
Rather than creating a method that matches the delegate's signature and then assigning the name of that method to the delegate, you can directly assign an unnamed delegate method by providing the implementation in line with the assignment.
145. How can you set the properties of a control?
Click on the control on the form, and then set the properties in the Properties window.
146. How do you make a button respond to being clicked?
Implement an event handler.
147. Name two ways to create an event handler.
The two ways to create an event handler are as follows:
• Go to the Properties window, click on the lightning button to open the events, then fill in a name or double-click next to the event to let Visual Studio 2005 create the name.
• Double-click on the control to create the default handler with a name provided by Visual Studio 2005.
148. What is recursion?
A method calling itself (such as calling Method A ( ) from within the body of Method A ( ))
149. What are the XML documentation comments?
XML documentation comments are preceded with three slashes, and are used to generate XML documents that can be used to document the application.
150. How do you see the code created by Visual Studio 2005 to create and initialize the controls on the form?
Click the ShowAllFiles button on the Solution Explorer and examine the “FormName”.Designer file.
151. What are the two most significant and commonly used namespaces for ASP.NET?
System.Web and System.Web.UI.Page
152. Where does ASP.NET code run?
On the server (though occasionally some Web Controls will write script to run on the client)
153. How do you ensure that a radio button selection or checkbox selection will be immediately posted to the server?
Making a non-postback event into a postback event is accomplished simply by setting the AutoPostBack property to true.
154. What is view state?
View state is the ability of ASP.NET pages to store the state of their controls during a post-back; the net effect is that the programmer does not have to write code to maintain the state of controls when a page is posted back to the server.
155. If you rename your class, all references to the class name will be updated, except that you will be warned that the reference in "markup" will not be changed. What does this mean?
You must update the Page directive to ensure that the Inherits property is set to the new class name.
156. If you click F5 to run your program, you may see a dialog box saying that debugging is not enabled. What should you do?
Click "Add a new web.config file with debugging enabled," and Visual Studio 2005 will create a web.config file for you, or alternatively, you can create the file yourself (by hand) and then add it to the project.
157. What are the three ways to add Server Controls to your form?
The three ways are as follows:
• Drag them from the toolbox.
• Write the code in the HTML markup window.
• Add them programmatically.
158. What property must every Server Control have?
Every Server Control must have this property:
Runat="Server"
159. Which control is used to enable data binding from a database to controls on a Web Form?
The DataSource control
160. When you create an “ASP: RadioButtonList” with “ASP: RadioButtonList” controls in it, what is sent to the browser?
A series of “input” elements of type "radio" with associated “label” controls all contained within a “table”.
161. How do you ensure that an action you want to take happens only the first time the page is shown, and does not happen if the user clicks a button or takes another action to post the page back to the server for processing?
Test for the IsPostBack property of the page. If true, the page has been posted back.
Use "Sealed"
2) Is it possible to create a private constructor in C#?
Yes,but no useful
3) Can you declare an override method to be static if the original method is not static?
No
No,its default value is Public.
6) Will the finally block get executed if an exception has not occurred?
Yes.
(Note:Due to problem of tag,In some places I replaced open tag by " and close tag by ")
No comments:
Post a Comment