C# Workshop - Week 8 Review Questions

Started by
0 comments, last by popcorn 15 years, 5 months ago
Chapters 20 - 23 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. True or False, any class or struct you define can specify how the standard C# operators are supposed to work on objects of that type?
  2. What are the overloadable Unary operators?
  3. What are the overloadable Binary operators?
  4. Is it possible to overload the conditional operators && and ||?
  5. What two modifiers are always required when overloading operators?
  6. How many parameters are there in a binary operator's operator method?
  7. What's true of at least one of the parameters to a binary operator?
  8. Is it possible to declare a virtual operator overload? Why or why not?
  9. Is operator overloading supported by Intermediate Language? If not, how does the compiler get around this?
  10. Why is it a good idea when creating overloaded operators to create static methods named the same as the operator you're overloading: ie Addition.
  11. What data type do the equality operators always return?
  12. True or False, a class that includes a declaration of the equality operator must also include the inequality operator?
  13. If you declare the equality and inequality operators you'll get a warning from the compiler for failure to provide overrides for which two methods?
  14. If the input parameter to a logical operator is null, what should the return value be?
  15. What is a hash code, as it pertains to GetHashCode?
  16. True or False, Just because two objects are equal doesn't mean they should return the same hash code.
  17. What keywords are used to declare explicit and implicit conversions?
  18. What does the "partial" keyword do on a class declaration?
  19. True or False, you are not allowed to use the partial class if the entire class is provided in a single location.
  20. True or False, because structures are more commonly associated with numeric or other simple types, operator overloading is much more common with structs?
  21. What interface must be implemented in order to be used with Array.Sort?
  22. What keyword is used to indicate something is an interface, as opposed to a struct or class?
  23. True or False, Interfaces generally contain no method implementations, but you can provide them if you like.
  24. True or False, the compiler requires that all interfaces begin with the letter I (aye) to indicate it's an Interface.
  25. Are methods the only member types which can exist in Interfaces? If not, what else can exist?
  26. While C# does not allow multiple inheritance, does it allow multiple interfaces? What does this mean?
  27. True or False, a class which implements an interface must include definitions for ALL of the methods, properties, and indexers specified in the interface.
  28. What does p/Invoke do?
  29. True or False, you'll generally want to tuck code away that uses p/Invoke into a easy-to-use wrapper.
  30. What namespace do you use when dealing with interoperability?
  31. If an external, unmanaged function you wish to call takes as a parameter or returns an unmanaged class or structure, what must you do first when using p/Invoke?
  32. What are Attributes?
  33. What attribute do you use to specify what DLL a p/Invoked method resides in?
  34. What does the 'extern' keyword mean?
  35. What's the URL for the Wiki which is designed to help people recreate structures and work with p/Invoke?
Good Luck! [Edited by - JWalsh on August 7, 2007 6:57:38 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
1. True or False, any class or struct you define can specify how the standard C# operators are supposed to work on objects of that type?
True.
2. What are the overloadable Unary operators?
The overloadable unary operators are: +, -, !, ~, ++, --, true and false.
3. What are the overloadable Binary operators?
The overloadable binary operators are: +, - , *, /, %, &, |, ^, == , !=, <, <=, >, >=, << and >>.
4. Is it possible to overload the conditional operators && and ||?
No it is not.
5. What two modifiers are always required when overloading operators?
The two modifiers needed are public and static.
6. How many parameters are there in a binary operator's operator method?
Two parameters.
7. What's true of at least one of the parameters to a binary operator?
It must be the same type as the class.
8. Is it possible to declare a virtual operator overload? Why or why not?
No it is not possible because the operands in the two declarations can never be the same, so they constitute distinct methods.
9. Is operator overloading supported by Intermediate Language? If not, how does the compiler get around this?
No it is not, the compiler gets around the issue of operator overloading by creating a method that can be substituted in place of the relevant operator being overloaded.
10. Why is it a good idea when creating overloaded operators to create static methods named the same as the operator you're overloading: ie Addition.
It is a good idea because it allows other languages that do not support operator overloading to use your code because those static methods for overloaded operators are supported in the CLS.
11. What data type do the equality operators always return?
Equality operators always return a bool.
12. True or False, a class that includes a declaration of the equality operator must also include the inequality operator?
True.
13. If you declare the equality and inequality operators you'll get a warning from the compiler for failure to provide overrides for which two methods?
The Equals and GetHashCode methods defined in System.Object.
14. If the input parameter to a logical operator is null, what should the return value be?
The return value should be false in this case.
15. What is a hash code, as it pertains to GetHashCode?
A hash code is a number that a program can use to assist in storing and retrieving objects.
16. True or False, Just because two objects are equal doesn't mean they should return the same hash code.
False, two equal objects must return the same hash code.
17. What keywords are used to declare explicit and implicit conversions?
The keywords explicit and implicit are used.
18. What does the "partial" keyword do on a class declaration?
The “partial” keyword indicates that a class may comprise of more than one file.
19. True or False, you are not allowed to use the partial class if the entire class is provided in a single location.
False.
20. True or False, because structures are more commonly associated with numeric or other simple types, operator overloading is much more common with structs?
True.
21. What interface must be implemented in order to be used with Array.Sort?
The IComparable interface.
22. What keyword is used to indicate something is an interface, as opposed to a struct or class?
The keyword interface.
23. True or False, Interfaces generally contain no method implementations, but you can provide them if you like.
False, interfaces do not contain any implementation, they are entirely overhead.
24. True or False, the compiler requires that all interfaces begin with the letter I (aye) to indicate it's an Interface.
False.
25. Are methods the only member types which can exist in Interfaces? If not, what else can exist?
Properties can also exist but they also must have empty bodies. Indexers as well.
26. While C# does not allow multiple inheritance, does it allow multiple interfaces? What does this mean?
It does allow multiple interfaces, it means that the class must implement all the methods that each interface contains.
27. True or False, a class which implements an interface must include definitions for ALL of the methods, properties, and indexers specified in the interface.
True.
28. What does p/Invoke do?
P/Invoke allows you to access code that is not available in the .NetFramework such as the windows API.
29. True or False, you'll generally want to tuck code away that uses p/Invoke into a easy-to-use wrapper.
True.
30. What namespace do you use when dealing with interoperability?
System.Runtime.InterOpServices.
31. If an external, unmanaged function you wish to call takes as a parameter or returns an unmanaged class or structure, what must you do first when using p/Invoke?

32. What are Attributes?
Attributes are information you can attach to a type or members of a type. The information is stored as metadata along with the compiled code.
33. What attribute do you use to specify what DLL a p/Invoked method resides in?
The StructLayoutAttribute.
34. What does the 'extern' keyword mean?
It means it is external to the program.
35. What's the URL for the Wiki which is designed to help people recreate structures and work with p/Invoke?
The URL is: http://www.pinvoke.net.

Whats the answer to question 31?
How about them apples?

This topic is closed to new replies.

Advertisement