🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

C# Workshop - Week 2 Review Questions

Started by
11 comments, last by JWalsh 16 years, 11 months ago
Chapter 3 - 6 Review Questions Greetings everyone. Each week I will post review questions and exercises in the weekly thread. Please try and answer them by yourself; either as you're reading over the chapters, or afterwards if you prefer. Once you've done so, feel free to look over the answers provided by others and submit your own answers if you've not yet seen them posted. Discussion about the quiz questions and answers is encouraged for clarification. Finally, experienced C# programmers may feel free to post quiz-like questions and exercises of their own.
  1. What do you call an assembly with an entry point?
  2. Is it possible to run multiple instantiations of an application on the same machine at the same time? Do they share or have a separate application domain?
  3. When does application setup occur?
  4. The entry point is always named what?
  5. What are the possible signatures of the main entry point method?
  6. True or false, the optional parameter in the entry point function may have any name, but must be of type string[]?
  7. What is contained in the optional parameter, if one is requested?
  8. Is it possible for a single class within an application to have more than one method which qualifies as an entry-point method?
  9. Is it possible for more than one class within an application to have a method which qualifies as an entry-point method, what would happen in such cases?
  10. True or False, in C# every method must be defined as a member of a class or struct?
  11. What is the purpose of an application's termination status code?
  12. If the application's entry-point method is defined to have a return type of "void", what's the application's termination status code always going to be?
  13. What are type declarations used for in C#?
  14. What kinds of members are permitted in class declarations?
  15. Is it ever possible for a class to contain different kinds of members (ie. field, event, method, etc...) with the same name?
  16. What are the 5 types of declaration spaces, how are they differentiated?
  17. What is true of two namespace declarations with the same fully qualified name, with regards to declaration space?
  18. When a class is derived from a base class, what is inherited?
  19. In specific, are private members inherited?
  20. Is it possible to give namespaces access restrictions? (ie. private, protected, public namespaces)
  21. True or false, all of the simple types such as int, char, ulong, bool, etc...are actually aliases for similarly named structs?
  22. What constitutes the members of an interface?
  23. What are the members of an Array?
  24. What are the members of a delegate?
  25. What are the possible declared accessibilities of a member, what do they mean?
  26. Do types declared within a namespace default to public or internal accessibility?
  27. What accessibility do class members default to?
  28. What accessibility do struct members default to?
  29. What accessibility do interface members default to?
  30. What accessibility do enum members default to?
  31. What is a member's accessibility domain?
  32. What 4 member types are characterized by their signatures?
  33. What is contained in a method's signature?
  34. Does a method's signature include it's return type?
  35. Signatures are the enabling mechanism for what feature in methods, instance constructors, indexers, and operators?
  36. Are 'ref' and 'out' considered part of a member's signature?
  37. Does "void MyFunc(ref int myInt)" have a different signature than "void MyFunc(out int myInt)"? Why or why not?
  38. What is the definition of an identifier's scope?
  39. Can scopes be nested?
  40. What happens when an inner scope re-declares an identifier with the same name as an outer scope identifier.
  41. What is the scope of a parameter declared in a method declaration?
  42. Within the scope of a class or struct is it possible to refer to a member in a textual position before the member's declaration?
  43. Within the scope of a local variable, is it possible to refer to the variable in a textual position before the variable's declaration?
  44. When does name hiding occur?
  45. When can name hiding occur as a result of nesting?
  46. When a name in an inner scope hides a name in an outer scope, what happens if that outer scope identifier is overloaded?
  47. Does name hiding as a result of nesting cause a warning or error? If so, how can this be dealt with.
  48. When can name hiding occur as a result of inheritance?
  49. Is it possible for a derived class to declare an overloaded operator with the same signature as an operator in a base class? What is this mean for name hiding?
  50. Does name hiding as a result of inheritance cause a warning or error?
  51. In the following example, which Method does MyMethod call in FurtherDerived?
    
    // Base class, provides a method "MyMethod" with an empty implementation
    class Base
    {
        public void MyMethod() {}
    }
    
    
    // Derived class, which inherits the base class's MyMethod, but then hides it by creating a new one
    class Derived : Base
    {
        new private void MyMethod() {}
    }
    
    
    // A class deriving from Derived, and thus being further derived.  It does not implement its
    // own 'MyMethod' so which MyMethod does it call  Base's or Derived's
    Class FurtherDerived : Derived
    {
        public void MyNewMethod()
        {
            MyMethod();
        }    
    }
    
    
    
    
  52. What is a fully qualified name? What does it contain?
  53. What construct implements the automatic memory management policies in C#?
  54. Does C# require that objects be destructed as soon as an object becomes available for destruction?
  55. Does C# require that memory be reclaimed as soon as an object has been destructed?
  56. Does C# require that destructors be run in any order, or in any particular thread?
  57. To avoid confusion and unexpected behavior it is generally a good idea for destructors to only perform cleanup on what? What should they not do?
  58. What are the two main categories of types in C#, how do they differ?
  59. What is the third type, and when is it available?
  60. Is it possible for operations on two value-type variables to effect the same memory? How about with reference types?
  61. What is the fully qualified name of the ultimate base class of all types in C#.
  62. Is it possible for a value-type variable to have a value of null? What about a reference variable?
  63. Can a value-type variable ever hold a value different than its compile-time type? What about a reference type?
  64. What is different about assignment to a value-type variable vs. assignment to a reference-type variable?
  65. What is the base class of all value types?
  66. Is it possible to declare a parameterless constructor for value types? Why or why not?
  67. What types of members can be declared within a struct?
  68. True for false, all simple types including int, float, char, long, and double have members?
  69. True for false, when all of the operands of an expression are simple type constants, it is possible for the compiler to evaluate the expression at compile-time?
  70. Is it possible to assign the 'const' keyword to user-defined structs? If not, how can this be resolved?
  71. What are the 9 integral types provided by C#?
  72. What are the checked and unchecked operators used for?
  73. What happens if there's an overflow in a "checked" context?
  74. What does NaN stand for and what does it mean?
  75. True or false, decimal values have greater precision but smaller range than floating point values? What does this imply about converting back and forth from decimal to float?
  76. Is there an implicit conversion from Decimal to float or double?
  77. What are the possible values of a Boolean variable?
  78. What standard conversions exist between bool and other types?
  79. What are the possible underlying types of an enum?
  80. Are variables of an enumeration type restricted to the values of the named constants?
  81. What are the available reference types?
  82. What's another name for an instance of a reference type?
  83. Which reference types can the value 'null' be used with?
  84. What is a delegate?
  85. Why is boxing important in C#?
  86. Is the boxing conversion from a value-type to an object implicit or explicit?
  87. True or False. A boxing conversion implies making a copy of the value being boxed?
  88. Is the unboxing conversion from a reference-type to a value-type implicit or explicit?
  89. In order for an unboxing conversion to a given value-type to succeed at run-time, what must be true?
  90. What do variables represent?
  91. What does it mean to say C# is a type-safe language?
  92. If a variable is considered initially assigned can it be used without assigning it a value?
  93. What are the 7 categories of variables in C#?
  94. When does a static variable come into existence? Are they considered initially assigned or unassigned?
  95. When does an instance variable come into existence? Are they initially assigned, or unassigned?
  96. When does a value parameter come into existence? Is it initially assigned, or unassigned?
  97. Are reference parameters initially assigned or unassigned?
  98. Are output parameters initially assigned or unassigned?
  99. Are local variables initially assigned or unassigned?
  100. Are local variables created in foreach statements or catch clauses initially assigned or unassigned?
  101. Which categories of variables are automatically initialized to their default values?
  102. What does it mean for a variable to be definitely assigned?
  103. Reads and writes of which types are atomic?
  104. Which types are not guaranteed to be atomic?
  105. What does a conversion enable?
  106. What are the two types of conversions, and what do they mean.
  107. True for false, the pre-defined implicit conversions always succeed and never cause exceptions to be thrown?
  108. Which types implicitly convert to the 'char' type?
  109. What is required for an implicit reference conversion?
  110. A conversion from long to ulong is an implicit conversion, provided the value of the variable being converted is not....what?
  111. Is it legal to explicitly cast a type to a type which there is an implicit conversion for? Why or why not?
  112. When converting from an enum to another type, how does the compiler treat the enum?
Chapter 3 - 6 Exercises Coming Soon ... [Edited by - JWalsh on July 18, 2007 10:03:35 PM]
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Advertisement
Alright, here's my attempt at answering the first few questions.

  1. An application.

  2. It is possible to run multiple instantiations of an application at the same time, each of which have a separate application domain.

  3. At the application's startup.

  4. Main.

  5. Main() or Main(string[]).

  6. False. The parameter must be of type string[].

  7. The command-line arguments.

  8. No.

  9. Yes, in which case an external mechanism must select the entry-point.

  10. True.

  11. The application's termination status code notifies success or failure to the execution environment.

  12. 0.

  13. They are used to declare classes, structs, enums, delegates and interfaces.

  14. Constants, fields, properties, methods, indexers, operators, events, instance and static constructors, destructors, and nested types.

  15. No, with the exception of overloaded constructors, methods, indexers and operators.

    • Global declaration space, which includes any types without an enclosing namespace.

    • Namespace declaration space, which includes all members belonging to a particular namespace.

    • Type declaration space, which includes members of types such as classes, structs, interfaces and enums.

    • Local variable declaration space, which includes local variables and constants declared within a block.

    • Label declaration space, which includes the labels used by goto and switch statements.

  16. They belong to the same declaration space.

  17. All of the members, except the static and instance constructors and the destructor.

  18. Yes, but their declared accessibility prevents them from being referenced within the derived class.

  19. No, namespaces can always be accessed publicly.

  20. True.

  21. All of the members (methods, properties, indexers, events) declared within the interface, as well as any inherited members from base interfaces.

  22. The members inherited from the System.Array class.

  23. The members inherited from the System.Delegate class.

    • public - Access not restricted.

    • protected - Access limited to the containing class and any derived classes.

    • private - Access limited to the containing class.

    • internal - Access limited to the containing program.

    • protected internal - Access limited to the containing program and any derived classes.

Is there an ETA on the exercises?
Heh, just as soon as I get them all written. Things came about, and I spent too much time working on the final project for the workshop.

As a result, each weak I must read the specification, write the introduction, overview, review questions, and exercises for both the current week, and as much as I can of the upcoming week. (So much for getting everything prepared ahead of time) This is in addition to trying to finish the final project, create project descriptions, and answer questions here on the forums.

And on top of that, my time spent on the Workshop now begins at about 8pm, as my day has just become split between my work as Lead Programmer and President of a software company...and author of a new book on game development.

So as much as it saddens me, my response to such questions in the future will have to be..."as soon as they are finished...as much as my free time will allow me to complete my tasks." [wink]

Cheers!
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
I suppose NDA's prohibit you from saying anything about which language or level the book is aimed at? Gizza clue! Is there a C or an X anywhere in the title?
Anyone else got any answers to the weekly review questions?
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Well, some may be wrong, but, here are mine. I'd rather be corrected than to think I answered correcly.

26. Do types declared within a namespace default to public or internal accessibility?

Internal

27. What accessibility do class members default to?

private
28. What accessibility do struct members default to?

private
29. What accessibility do interface members default to?

Public
30. What accessibility do enum members default to?

Public
31. What is a member's accessibility domain?

Section of a program where the member is accessible
32. What 4 member types are characterized by their signatures?

Methods, Instance Constructors, Indexers and Operators

33. What is contained in a method's signature?

The name of the method and the type and kind of its formal parameters
34. Does a method's signature include it's return type?

No
35. Signatures are the enabling mechanism for what feature in methods, instance constructors, indexers, and operators?

Overloading
36. Are 'ref' and 'out' considered part of a member's signature?

Yes
37. Does "void MyFunc(ref int myInt)" have a different signature than "void MyFunc(out int myInt)"? Why or why not?

No, ref and out cannot be used solely to distinguish different signatures
38. What is the definition of an identifier's scope?

39. Can scopes be nested?

yes
40. What happens when an inner scope re-declares an identifier with the same name as an outer scope identifier.


41. What is the scope of a parameter declared in a method declaration?


42. Within the scope of a class or struct is it possible to refer to a member in a textual position before the member's declaration?

No
43. Within the scope of a local variable, is it possible to refer to the variable in a textual position before the variable's declaration?

No
44. When does name hiding occur?

When scopes overlap through inheritance and nesting
45. When can name hiding occur as a result of nesting?

Nesting namespaces or types within other namespaces.
46. When a name in an inner scope hides a name in an outer scope, what happens if that outer scope identifier is overloaded?

It is still hidden by the inner scope
47. Does name hiding as a result of nesting cause a warning or error? If so, how can this be dealt with.

Error
48. When can name hiding occur as a result of inheritance?

When classes and structs redeclare inherited base classes.
49. Is it possible for a derived class to declare an overloaded operator with the same signature as an operator in a base class? What is this mean for name hiding?

Yes, if it is a public class that the derived class is based off of and uses the new.
50. Does name hiding as a result of inheritance cause a warning or error?

Warning
51. In the following example, which Method does MyMethod call in FurtherDerived?


52. What is a fully qualified name? What does it contain?

Complete hierarchical representation of the path to the name.
53. What construct implements the automatic memory management policies in C#?

Garbage Collector
54. Does C# require that objects be destructed as soon as an object becomes available for destruction?

No
55. Does C# require that memory be reclaimed as soon as an object has been destructed?

No
56. Does C# require that destructors be run in any order, or in any particular thread?

Can be run in any order or thread
57. To avoid confusion and unexpected behavior it is generally a good idea for destructors to only perform cleanup on what? What should they not do?

Their own object's fields. Don’t perform any action on static fields or referenced objects
58. What are the two main categories of types in C#, how do they differ?

Value types and reference types
59. What is the third type, and when is it available?

Pointers, but they are only available in unsafe code.
60. Is it possible for operations on two value-type variables to effect the same memory? How about with reference types?

Not with value-types as they contain there data. Reference types can effect the same memory.
61. What is the fully qualified name of the ultimate base class of all types in C#.

object
62. Is it possible for a value-type variable to have a value of null? What about a reference variable?

No, Yes
63. Can a value-type variable ever hold a value different than its compile-time type? What about a reference type?

No, Yes
64. What is different about assignment to a value-type variable vs. assignment to a reference-type variable?

Value type creates a copy of the value being assigned. Reference just copies the reference to the object, not the object itself
65. What is the base class of all value types?

System.ValueType
66. Is it possible to declare a parameterless constructor for value types? Why or why not?

Yes, the default constructor is parameterless.
67. What types of members can be declared within a struct?

Value and reference
68. True for false, all simple types including int, float, char, long, and double have members?

True
69. True for false, when all of the operands of an expression are simple type constants, it is possible for the compiler to evaluate the expression at compile-time?

True

Of course there are a few I did not answer either. Why? Confusion for the most part I would say.

Shawn

*Edit* Had all the questions in there, edited it so others can post some answers.
Quote: Original post by JWalsh
Anyone else got any answers to the weekly review questions?


Are we supposed to post our answers to this thread, I've pretty much answered all the questions bar maybe a few which I attempted to answer but am unsure about.

Anyway of the questions which I was unsure about are:

16. What are the 5 types of declaration spaces, how are they differentiated?

The 5 types of declaration spaces are:
1. Global declaration space
2. Variable declaration space
3. Label declaration space

I only managed to find 3 declaration spaces, what are the other 2?

61. What is the fully qualified name of the ultimate base class of all types in C#.

Object????

Actually I pretty sure object is the ultimate base class but am unsure about the fully qualified name part.

63. Can a value-type variable ever hold a value different than its compile-time type? What about a reference type?

No for value type, yes for reference type.

97. Are reference parameters initially assigned or unassigned?

It is initially unassigned.

106. What are the two types of conversions, and what do they mean.

The two type of conversion are:
1. Implicit – when the type being converted can fit into the new type.
2. Explicit – when the type being converted might not fit into the new type.

111. Is it legal to explicitly cast a type to a type which there is an implicit conversion for? Why or why not?

Not sure about this one.



How about them apples?
I have answered most of them here. I can upload them to my homepage as .pdf/.doc later if it has any interest.
*EDIT*: I uploaded the first week's questions and answers here and I will upload the rest today. There's also a couple of links etc. If there are grave errors or the like, point it out to me, and I will correct them, in case people want to use them as a reference (pdf is slightly more readable than html in forums)

1. What do you call an assembly with an entry point?
An application.
2. Is it possible to run multiple instantiations of an application on the same machine at the same time? Do they share or have a separate application domain?
It is possible to run multiple instantations and they all have a separate application domain.
3. When does application setup occur?
When the environment calls a designated method, referred to as the application’s entry point.
4. The entry point is always named what?
The entry point is always a static method called the Main()and has one of the following signatures:
5. What are the possible signatures of the main entry point method?
The entry point can have one of the following signatures:
static void Main() {...}
static void Main(string[] args) {...}
static int Main() {...}
static int Main(string[] args) {...}
6. True or false, the optional parameter in the entry point function may have any name, but must be of type string?
True – refer to question 5 above.
7. What is contained in the optional parameter, if one is requested?
The optional parameter, if present, contains command line arguments created by the execution environment.
8. Is it possible for a single class within an application to have more than one method which qualifies as an entry-point method?
Yes, it is possible.
9. Is it possible for more than one class within an application to have a method which qualifies as an entry-point method, what would happen in such cases?
Yes. An external mechanism (for instance a command-line compiler option) should be created to choose which main() method to act as main entry point.
10. True or False, in C# every method must be defined as a member of a class or struct?
True.
11. What is the purpose of an application's termination status code?
To evaluate a status of success or failure to the execution environment.
12. If the application's entry-point method is defined to have a return type of "void", what's the application's termination status code always going to be?
0
13. What are type declarations used for in C#?
Type declarations are used to define classes, structs, interfaces, enums and delegates.
14. What kinds of members are permitted in class declarations?
Constants, fields, methods, properties, events, indexers, operators, instance constructors, static constructors, destructors and nested types.
15. Is it ever possible for a class to contain different kinds of members (ie. field, event, method, etc...) with the same name?
No.
16. What are the 5 types of declaration spaces, how are they differentiated?
Global declaration space: Namespace-member-declarations with no enclosing namespace-declaration are combined in the global declaration space.
“Class/struct/interface” declaration space: Names are introduced in this declaration space through class/struct/interface-member-declarations. Except for overloaded instance constructor declarations and static constructor declarations, the names of the members cannot be the same as the name of the class or the struct. Classes, structs and indexers permit the declaration of overloaded methods and indexers. Classes and structs permit the declaration of overloaded instance constructors and operators. Classes permit the declaration of multiple methods with the same name, provided they have different signatures. Base classes/interfaces do not contribute to the declaration space of a class/interface. Hence, a derived class is permitted to declare a member with the same name as a member of the base class. Such a member is said to hide the inherited member.
Enumeration declaration space: An enumeration creates a new declaration space. Members are added through enum-member-declarations.
Label declaration space: Each block or switch block creates a separate declaration space for labels. Names are introduced in this space through labeled-statements and are accessed through goto-statements. Label declaration spaces include nested blocks, which means that it is not possible to declare labels with the same names in the nested blocks of the label declaration space.
Local variable declaration space: If a block is the body of an instance constructor, method, or operator declaration, or a get or set accessor for an indexer declaration, the parameters declared in such a declaration are members of the block’s local variable declaration space. Note that the local variable declaration space includes any nested blocks, which means that it is not possible to declare members with the same names in nested blocks.
17. What is true of two namespace declarations with the same fully qualified name, with regards to declaration space?
They contribute to the same declaration space.
18. When a class is derived from a base class, what is inherited?
All members of the base class, except instance constructors, destructors and static constructors.
19. In specific, are private members inherited?
Yes, inheritance extends to any member but instance constructors, destructors and static constructors. The derived member may, however not be accessible by the derived class because of specific access restrictions.
20. Is it possible to give namespaces access restrictions? (ie. private, protected, public namespaces)
No, namespaces are always publicly available.
21. True or false, all of the simple types such as int, char, ulong, bool, etc...are actually aliases for similarly named structs?
True.
22. What constitutes the members of an interface?
The members of an interface are the members declared in that interface and the members in all base interfaces.
23. What are the members of an Array?
The members inherited from the class System.Array.
24. What are the members of a delegate?
The members inherited from the class System.Delegate.
25. What are the possible declared accessibilities of a member, what do they mean?
Public: Access not limited
Protected: Access limited to the containing class or types derived from the containing class
Internal: Access limited to this program
Protected internal: Access limited to this program or types derived from the containing class
Private: Access limited to the containing type
26. Do types declared within a namespace default to public or internal accessibility?
Namespaces implicitly have public declared accessibility. Access modifiers are not allowed on namespace declarations.
27. What accessibility do class members default to?
Class members default to private accessibility.
28. What accessibility do struct members default to?
Struct members default to private accessibility.
29. What accessibility do interface members default to?
Interface members implicitly have public declared accessibility.
30. What accessibility do enum members default to?
Enum members implicitly have public declared accessibility.
31. What is a member's accessibility domain?
The accessibility domain of a member is the part of the code where access to the member is permitted. Specifically:
The accessibility domain of predefined types (ex object, int, double) is unlimited
T is a top-level type in a program P. M is a nested member declared in T.
 If the declared accessibility of T is public the accessibility domain of T is the program text of P and of programs referencing P
 If the declared accessibility of T is internal the accessibility domain of T is the program text of P
 If the declared accessibility of M is public the accessibility domain of M is the accessibility domain of T
 If the declared accessibility of M is protected internal let D be the union of the program text of P and the program text of any type derived from T , which is declared outside of P. The accessibility domain of M is the intersection of the accessibility domain of T with D.
 If the declared accessibility of M is protected, let D be the union of the program text of T and the program text of any type derived from T. The accessibility domain of M is the intersection of the accessibility domain of T with D.
 If the declared accessibility of M is internal, the accessibility domain of M is the intersection of accessibility domain of T with the program text of P.
 If the declared accessibility of M is private, the accessibility domain of M is the program text of T.
Conclusively on the above it can be said that the accessibility of a nested member is at least the program text of the type in which the member is declared and the accessibility is never more inclusive than the accessibility domain of the type in which the member is declared. SEE PAGE 58-59 FOR VERY ILLUSTRATIVE EXAMPLES
32. What 4 member types are characterized by their signatures?
Methods, instance constructors, indexers and operators.
33. What is contained in a method's signature?
The name of the method as well as the type and kind of each of its formal parameters.
34. Does a method's signature include it's return type?
No, and neither is the optional params modifier for the rightmost parameter included.
35. Signatures are the enabling mechanism for what feature in methods, instance constructors, indexers, and operators?
Overloading.
36. Are 'ref' and 'out' considered part of a member's signature?
Yes.
37. Does "void MyFunc(ref int myInt)" have a different signature than "void MyFunc(out int myInt)"? Why or why not?
Yes, the signatures are different. Yet they can’t be declared in the same declaration space, because even though ref and int are considered part of a member’s signature, they must not be the only difference when overloading the member. If the signatures differ only in ref and int it will result in a compile-time error.
38. What is the definition of an identifier's scope?
An identifier’s scope is the region of program text where the identifier can be referred to without qualification.
39. Can scopes be nested?
Yes.
40. What happens when an inner scope re-declares an identifier with the same name as an outer scope identifier.
Since it is not possible to declare a local variable with the same name as a local variable in an enclosing block, it is no longer possible to reference the identifier from the outer scope without qualifying it. The identifier from the outer scope is then said to be hidden.
41. What is the scope of a parameter declared in a method declaration?
The method body of that method declaration.
42. Within the scope of a class or struct is it possible to refer to a member in a textual position before the member's declaration?
Yes.
43. Within the scope of a local variable, is it possible to refer to the variable in a textual position before the variable's declaration?
No.
44. When does name hiding occur?
Name hiding occurs when scopes overlap through either nesting or inheritance.
45. When can name hiding occur as a result of nesting?
It can occur as a result of nesting a namespace or a type within a namespace, nesting a type within a class or a struct or as a result of parameter and local variable declarations.
46. When a name in an inner scope hides a name in an outer scope, what happens if that outer scope identifier is overloaded?
All the overloaded occurrences of that identifier are hidden.
47. Does name hiding as a result of nesting cause a warning or error? If so, how can this be dealt with.
An error.
48. When can name hiding occur as a result of inheritance?
It occurs when a class or a struct redeclares a name that was inherited from a base class.
49. Is it possible for a derived class to declare an overloaded operator with the same signature as an operator in a base class? What is this mean for name hiding?
No, it is not possible for a derived class to declare an operator with the same identifier as an operator in the base class. This means that operators never hide one another.
50. Does name hiding as a result of inheritance cause a warning or error?
It results in a warning.
51. In the following example, which Method does MyMethod call in FurtherDerived?
// Base class, provides a method "MyMethod" with an empty implementationclass Base{    public void MyMethod() {}}// Derived class, which inherits the base class's MyMethod, but then hides it by creating a new oneclass Derived : Base{    new private void MyMethod() {}}// A class deriving from Derived, and thus being further derived.  It does not implement its// own 'MyMethod' so which MyMethod does it call  Base's or Derived'sClass FurtherDerived : Derived{    public void MyNewMethod()    {        MyMethod();    }    }

It calls Base.MyMethod() since Derived.MyMethod() is declared with the new keyword which means that the hiding of the method from the base class only extends to the scope of the method from the derived class. Since the method is private, the scope doesn’t extend to MyNewMethod.
52. What is a fully qualified name? What does it contain?
Every type and namespace has a fully qualified name that uniquely identifies them. It is determined as follows. If N is part of the global namespace, then the fully qualified name is N, else the fully qualified name is S.N, where S is the fully qualified name of the namespace or type in which N is declared.
53. What construct implements the automatic memory management policies in C#?
The garbage collector.
54. Does C# require that objects be destructed as soon as an object becomes available for destruction?
No.
55. Does C# require that memory be reclaimed as soon as an object has been destructed?
No.
56. Does C# require that destructors be run in any order, or in any particular thread?
No.
57. To avoid confusion and unexpected behavior it is generally a good idea for destructors to only perform cleanup on what? What should they not do?
They should only perform cleanup on data stored in their objects’ own fields and not on referenced objects or static fields.
58. What are the two main categories of types in C#, how do they differ?
Value types and reference types.
59. What is the third type, and when is it available?
The third type is pointers, but it is only available in unsafe code.
60. Is it possible for operations on two value-type variables to effect the same memory? How about with reference types?
It is not possible for value types, since the data is locally contained, but it is possible for reference types, since they only contain references to the data and so operations on one reference type can affect the object that is referenced by another reference type.
61. What is the fully qualified name of the ultimate base class of all types in C#.
object
62. Is it possible for a value-type variable to have a value of null? What about a reference variable?
No, value types cannot hold a null value. It is possible for reference types.
63. Can a value-type variable ever hold a value different than its compile-time type? What about a reference type?
?
64. What is different about assignment to a value-type variable vs. assignment to a reference-type variable?
When a value is assigned to a value type variable, that value is directly stored, while reference-type variables store a reference to the value.
65. What is the base class of all value types?
System.ValueType which is derived from object.
66. Is it possible to declare a parameterless constructor for value types? Why or why not?
Yes, a parameterless constructor will for all value types create a value produced by a bit pattern of all zeros.
67. What types of members can be declared within a struct?
Constants, fields, methods, properties, indexers, operators, instance constructors, static constructors and nested types.
68. True or false, all simple types including int, float, char, long, and double have members?
True.
69. True or false, when all of the operands of an expression are simple type constants, it is possible for the compiler to evaluate the expression at compile-time?
True.
70. Is it possible to assign the 'const' keyword to user-defined structs? If not, how can this be resolved?
No, but a constant-like effect can be achieved by utilizing the static readonly modifiers.
71. What are the 9 integral types provided by C#?
Sbyte, byte, short, ushort, int, uint, long, ulong, char
72. What are the checked and unchecked operators used for?
They are used to control over- and underflow for arithmetic-type operations.
73. What happens if there's an overflow in a "checked" context?
It either produces a compile-time error or throws a System.OverflowException at runtime.
74. What does NaN stand for and what does it mean?
It stands for Not-a-Number. It is a value produced by invalid floating point operations.
75. True or false, decimal values have greater precision but smaller range than floating point values? What does this imply about converting back and forth from decimal to float?
Conversion from floating point values to decimals may result in overflow exceptions and the other way round it might result in loss of precision.
76. Is there an implicit conversion from Decimal to float or double?
No, for the above stated reasons, there are no implicit conversions.
77. What are the possible values of a Boolean variable?
true or false.
78. What standard conversions exist between bool and other types?
79. What are the possible underlying types of an enum?
The underlying type must be an integral-type.
80. Are variables of an enumeration type restricted to the values of the named constants?
No.
81. What are the available reference types?
Class, interface, array, delegate.
82. What's another name for an instance of a reference type?
An object.
83. Which reference types can the value 'null' be used with?
With all reference types.
84. What is a delegate?
A delegate is a data structure that references one or more methods. For instance methods it also refers their corresponding object instances.
85. Why is boxing important in C#?
Boxing is an important of the unified type system, since it allows value types to be converted to and from object. It thus provides a bridge between value types and reference types.
86. Is the boxing conversion from a value-type to an object implicit or explicit?
Implicit.
87. True or False. A boxing conversion implies making a copy of the value being boxed?
True.
88. Is the unboxing conversion from a reference-type to a value-type implicit or explicit?
Explicit.
89. In order for an unboxing conversion to a given value-type to succeed at run-time, what must be true?
The value of the source operand must reference an object that was previously created by boxing a value of that value type.
90. What do variables represent?
Storage locations.
91. What does it mean to say C# is a type-safe language?
It means that a C# compiler assures that the value stored in a variable is always of the appropriate type.
92. If a variable is considered initially assigned can it be used without assigning it a value?
Yes, because it is always considered definitely assigned.
93. What are the 7 categories of variables in C#?
Static variables, instance variables, array elements, value parameters, reference parameters, output parameters and local variables.
94. When does a static variable come into existence? Are they considered initially assigned or unassigned?
A static variable comes into existence before the execution of the static constructor. A static variable is considered initially assigned.
95. When does an instance variable come into existence? Are they initially assigned, or unassigned?
For classes, instance variables come into existence whenever a new instance of the containing class is created and for structs the instance variable comes into existence whenever the struct does. Instance variables in classes are considered initially assigned and instance variables in structs have the same assignment status as the containing struct.
96. When does a value parameter come into existence? Is it initially assigned, or unassigned?
A value parameter comes into existence upon the invocation of a function member in which the parameter is involved. A value parameter is initially assigned.
97. Are reference parameters initially assigned or unassigned?
Initially assigned.
98. Are output parameters initially assigned or unassigned?
Initially unassigned.
99. Are local variables initially assigned or unassigned?
Initially unassigned.
100. Are local variables created in foreach statements or catch clauses initially assigned or unassigned?
A local variable created in a foreach statement or a specific catch-clause is considered initially assigned throughout its entire scope.
101. Which categories of variables are automatically initialized to their default values?
Static variables, instance variables of class instances and array elements.
102. What does it mean for a variable to be definitely assigned?
A variable is said to be definitively assigned if the compiler can prove, by a particular static flow analysis, that the variable has been automatically initialized or has been the target of at least one assignment.

I haven't had the time to complete the last ten or so questions, will edit this post later.

[Edited by - CKolding on July 21, 2007 10:48:58 AM]
Will the "correct" answers for all questions be posted for comparison to our own answers? That way if we answered incorrectly, we can get further clarification of what we missed.

Thanks,

Shawn

Maybe a separate thread entitled Chapter 3-6 Review Answers! or something? Just a suggestion.

This topic is closed to new replies.

Advertisement