C# Workshop - Week 9 Review Questions

Started by
0 comments, last by popcorn 16 years, 7 months ago
Chapters 24 - 26 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 is an event?
  2. Why is an event considered type-safe?
  3. In which namespace is the EventHandler delegate defined?
  4. What is generally considered the base class for argument classes sent to event handlers?
  5. What must an event handler share in common with a delegate in order to be used with an event?
  6. True or False, An event member within a class will be null if there are no event handlers registered to listen for events?
  7. True or False, you can attach more than one event handler to an event, and triggering the event calls all event handlers in order.
  8. True or False, C# 2.0 simplified the syntax of registering event handlers by just requiring the name of the method, rather than creation of an event handler object.
  9. What purpose does the timer class serve?
  10. How do you define an anonymous method for use by events?
  11. Which namespace provides essential support for file input and output for both binary and text files?
  12. Which namespace provides essential support for file input and output when working with XML files?
  13. What is the difference between a file and a stream in .NET?
  14. True or False, you can define a stream of data coming from a file, over a network, or even directly from memory?
  15. Is it possible to create instances of class Stream?
  16. What are the 4 concrete types which inherit Stream?
  17. What are the 4 boolean properties defined by a stream, and what do they mean?
  18. What method is used to close a stream?
  19. Why is it important to always construct a file stream within a try block?
  20. True or False, unless you specify a FileShare argument to the FileStream constructor, all other processes on the machine will be able to access the file.
  21. True or false, when you only need to read from a file, it's common to allow other processes to read from it as well.
  22. For streams which have a CanSeek property set to true, what does the Position property do?
  23. What method on the Stream class is used to read a single byte? Which is used to read an array of bytes?
  24. What is the return value of the above two methods, how are they different?
  25. True or False, You should always explicitly call Close on a FileStream when you're done using it.
  26. What are the 2 concrete classes for writing text? How are they different?
  27. What are the 2 concrete classes for reading text?
  28. How do you specify the encoding to be used with a StreamWriter object?
  29. True or False, by default, any file opened for writeable access will have it's contents destroyed?
  30. What's the easiest way to obtain an encoding object which identifies the encoding you're looking to use?
  31. By default, Unicode is Big-endian or Little-endian?
  32. What is UTF-8?
  33. Which RFC file is UTF-8 described in?
  34. When you convert Unicode to ASCII for stream output, any character outside of the ASCII range will appear in the stream as a what?
  35. What does the AutoFlush property on the StreamWriter object do when set to true?
  36. What does the ReadToEnd method of the StreamReader do?
  37. True or False, when storing an array of data to a file, the size of the array is stored before the array, for easy reading.
  38. True or False, when storing a string to a file, the length of the string is stored before the array, for easy reading.
  39. Why is it important to put read methods inside of a try/catch block?
  40. What class and method might you use to get a comma separated list of all drives on a computer?
  41. What class do you use to get information about a drive?
  42. What Enumeration do you use when trying to get the path to system and user defined special folders?
  43. What class do you use to make it easier to parse file and directory names, as well as complete paths?
  44. What are the static and non-static class counterparts for working with Directory and File Info?
  45. What property of the DirectoryInfo class to do you use to determine if a directory exists?
  46. If you create a DirectoryInfo object on a directory that does not exist, and then call create, will the "Exists" property be true? If not, what must be done to make it true?
  47. True or False, once a string is created, neither the length of the string nor individual characters within the string can be changed.
  48. Although strings are immutable, what class can you use which allows modification of parts of a string?
Good Luck! [Edited by - JWalsh on August 8, 2007 12:46:31 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. What is an event?
An event is a type-safe mechanism essentially for defining call-back functions.
2. Why is an event considered type-safe?
An event is considered type-safe because the call-back function must have a specific signature defined by a delegate.
3. In which namespace is the EventHandler delegate defined?
In the System namespace.
4. What is generally considered the base class for argument classes sent to event handlers?
EventArgs.
5. What must an event handler share in common with a delegate in order to be used with an event?
It must have the same return type and parameters.
6. True or False, An event member within a class will be null if there are no event handlers registered to listen for events?
True.
7. True or False, you can attach more than one event handler to an event, and triggering the event calls all event handlers in order.
True.
8. True or False, C# 2.0 simplified the syntax of registering event handlers by just requiring the name of the method, rather than creation of an event handler object.
True.
9. What purpose does the timer class serve?
The timer class notifies a class when a period of time has passed.
10. How do you define an anonymous method for use by events?
Use the compound assignment statement followed by the keyword delegate(p224).
11. Which namespace provides essential support for file input and output for both binary and text files?
The System.IO namespace.
12. Which namespace provides essential support for file input and output when working with XML files?
System.XML.
13. What is the difference between a file and a stream in .NET?
In .NET a file is a collection of data stored on a disc. A stream is a file that is opened for reading and writing.
14. True or False, you can define a stream of data coming from a file, over a network, or even directly from memory?
True.
15. Is it possible to create instances of class Stream?
No because it is an abstract class.
16. What are the 4 concrete types which inherit Stream?
The 4 concrete types which inherit Stream are:
1. BufferedStream
2. FileStream
3. MemoryStream
4. NetworkStream
17. What are the 4 boolean properties defined by a stream, and what do they mean?
The 4 boolean properties defined by a stream are:
1. CanRead – if true you can use ReadByte and Read
2. CanWrite – if true you can use WriteByte and Write
3. CanSeek – if true you can use the Length property and Position as well as the seek method.
4. CanTimeOut – if true you can use the ReadTimeOut and WriteTimeOut properties.
18. What method is used to close a stream?
The close method.
19. Why is it important to always construct a file stream within a try block?
It is important to always construct a file stream within a try block so that you can recover from any problems regarding the existence or non-existence of a file.
20. True or False, unless you specify a FileShare argument to the FileStream constructor, all other processes on the machine will be able to access the file.
False.
21. True or false, when you only need to read from a file, it's common to allow other processes to read from it as well.
True.
22. For streams which have a CanSeek property set to true, what does the Position property do?
The position property allows you to seek to any point within a file.
23. What method on the Stream class is used to read a single byte? Which is used to read an array of bytes?
The ReadByte method is used to read a single byte. The Read method is used to read an array of bytes.
24. What is the return value of the above two methods, how are they different?
They both return int values. The int returned in ReadByte indicates the next byte in the file, a -1 indicates an attempt to read past the end of the file. The int returned in Read is the number of byte actually read.
25. True or False, You should always explicitly call Close on a FileStream when you're done using it.
True.
26. What are the 2 concrete classes for writing text? How are they different?
The 2 concrete classes for writing text are:
1. StreamWriter
2. StringWriter
They differ in that:
27. What are the 2 concrete classes for reading text?
The 2 concrete classes for reading text are:
1. StreamReader
2. StringReader
28. How do you specify the encoding to be used with a StreamWriter object?
In a StreamWriter object you specify the encoding to be used by passing an object of type Encoding as a parameter in the construction of the object.
29. True or False, by default, any file opened for writeable access will have it's contents destroyed?
True.
30. What's the easiest way to obtain an encoding object which identifies the encoding you're looking to use?
The easiest way to obtain an encoding object which identifies the encoding you’re looking to use is to use the static properties of the encoding class.
31. By default, Unicode is Big-endian or Little-endian?
Little-endian.
32. What is UTF-8?
UTF-8 is a way to encode characters in Unicode without using any zero bytes.
33. Which RFC file is UTF-8 described in?
RFC 2279.
34. When you convert Unicode to ASCII for stream output, any character outside of the ASCII range will appear in the stream as a what?
A question mark.
35. What does the AutoFlush property on the StreamWriter object do when set to true?
It performs a flush on the buffer after every write.
36. What does the ReadToEnd method of the StreamReader do?
The ReadToEnd method of StreamReader returns everything from the current position to the end of the file.
37. True or False, when storing an array of data to a file, the size of the array is stored before the array, for easy reading.
False.
38. True or False, when storing a string to a file, the length of the string is stored before the array, for easy reading.
False
39. Why is it important to put read methods inside of a try/catch block?
In case the read fails.
40. What class and method might you use to get a comma separated list of all drives on a computer?
The Enviroment class and the GetLogicalDrives method.
41. What class do you use to get information about a drive?
The DriveInfo class.
42. What Enumeration do you use when trying to get the path to system and user defined special folders?
The Enviroment.SpecialFolder enumeration.
43. What class do you use to make it easier to parse file and directory names, as well as complete paths?
The Path class.
44. What are the static and non-static class counterparts for working with Directory and File Info?

45. What property of the DirectoryInfo class to do you use to determine if a directory exists?
The Exists property.
46. If you create a DirectoryInfo object on a directory that does not exist, and then call create, will the "Exists" property be true? If not, what must be done to make it true?
No it will not be true, you must call the Refresh method to update the DirectoryInfo information.
47. True or False, once a string is created, neither the length of the string nor individual characters within the string can be changed.
True.
48. Although strings are immutable, what class can you use which allows modification of parts of a string?
The StringBuilder class.

Unsure about q26, 29, 37, 39 and 44.
How about them apples?

This topic is closed to new replies.

Advertisement