You are on page 1of 3

http://computersociety.safaribooksonline.com/print?xmlid=97805961550...

Username: Kyle Daly Book: Learning C# 3.0. No part of any chapter or book may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher of the book or chapter. Redistribution or other use that violates the fair use privilege under U.S. copyright laws (see 17 USC107) or that otherwise violates these Terms of Service is strictly prohibited. Violators will be prosecuted to the full extent of U.S. Federal and Massachusetts laws.

Appendix A. Answers to Quizzes and Exercises


Chapter 1: C# and .NET Programming Chapter 2: Visual Studio 2008 and C# Express 2008 Chapter 3: C# Language Fundamentals Chapter 4: Operators Chapter 5: Branching Chapter 6: Object-Oriented Programming Chapter 7: Classes and Objects Chapter 8: Inside Methods Chapter 9: Basic Debugging Chapter 10: Arrays Chapter 11: Inheritance and Polymorphism Chapter 12: Operator Overloading Chapter 13: Interfaces Chapter 14: Generics and Collections Chapter 15: Strings Chapter 16: Throwing and Catching Exceptions Chapter 17: Delegates and Events Chapter 18: Creating Windows Applications Chapter 19: Windows Presentation Foundation

1 of 3

5/9/2012 6:24 PM

http://computersociety.safaribooksonline.com/print?xmlid=97805961550...

Chapter 20: ADO.NET and Relational Databases Chapter 21: LINQ

A.1. Chapter 1: C# and .NET Programming


A.1.1. Quiz Solutions
Solution to Question 1-1. The Common Language Runtime (CLR) is the component of the .NET Framework that allows you to compile and execute applications written in either C# or Visual Basic .NET. Solution to Question 1-2. The .NET Framework specifies how .NET constructs intrinsic types, classes, interfaces, and so forth. Solution to Question 1-3. Calling C# a "safe" language refers to "type safety"the ability of the compiler to ensure that the objects you create are of the expected type. Solution to Question 1-4. Keywords are reserved for use by the language and cannot be used to identify objects or methods you create. Solution to Question 1-5. The job of the compiler is to turn your source code into Microsoft Intermediate Language (MSIL). Solution to Question 1-6. The Microsoft Intermediate Language is the native language for .NET and is compiled into an executable application by the Just In Time (JIT) compiler. Solution to Question 1-7. The Just In Time compiler turns your MSIL code into an application in memory. Solution to Question 1-8. Namespaces are used to ensure that identifiers are unique across libraries of classes. In other words, they ensure that a name that you use in your code doesn't conflict with a name used by Microsoft, or anybody else. Solution to Question 1-9. A string is a class with many abilities and uses, but in its simplest form, a string is text enclosed in double quotation marks. Solution to Question 1-10. The four kinds of applications you can build with Visual Studio 2008 are Console, Windows, Web, and Web Services applications.

A.1.2. Exercise Solution

2 of 3

5/9/2012 6:24 PM

http://computersociety.safaribooksonline.com/print?xmlid=97805961550...

Solution to Exercise 1-1. Write an application that emits the words "What a great book!" to the console window. Hint: open Visual Studio, create a console application, and, if you get stuck, consider copying or modifying the code shown in the chapter. Remember, these exercises are for your own edification, no one is grading them, and making mistakes is an opportunity to explore and learn morethis is true in just about everything except nuclear physics. So, Don't Panic! To accomplish this exercise, you simply need to follow the same steps that you did to create Hello World in the chapter. Create a new console application from the Start Page, and give it whatever name you like, although "Exercise 1-1" is a reasonable name. When Visual Studio creates a code skeleton for you, click inside the Main( ) method and insert the following line:
Console.WriteLine("What a great book!");

Notice that we didn't use the System namespace in this line, because the using statement takes care of that. The exact code you use may vary somewhat, depending on what you chose to name your namespace and your class, and how you phrased your string, but one solution appears in Example A-1.

Example A-1. One solution to Exercise 1-1

using using using using

System; System.Collections.Generic; System.Linq; System.Text;

namespace Exercise_1_1 { class Program { static void Main(string[] args) { Console.WriteLine("What a great book!"); } } }

3 of 3

5/9/2012 6:24 PM

You might also like