O'Reilly logo

Beginning C# 6.0 Programming with Visual Studio 2015 by Jon D. Reid, Jacob Vibe Hammer, Benjamin Perkins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

APPENDIX

Exercise Solutions

There are no exercises in Chapters 1 and 2.

Chapter 3 Solutions

Exercise 1

super.smashing.great

Exercise 2

b), as it starts with a number, and e), as it contains a full stop.

Exercise 3

No, there is no theoretical limit to the size of a string that may be contained in a string variable.

Exercise 4

The * and / operators have the highest precedence here, followed by +, %, and finally +=. The precedence in the exercise can be illustrated using parentheses as follows:

resultVar += (((var1 * var2) + var3) % (var4 / var5));

Exercise 5

using static System.Console;
using static System.Convert;
static void Main(string[] args)
{
   int firstNumber, secondNumber, thirdNumber, fourthNumber;
   WriteLine("Give me a number:");
   firstNumber = ToInt32(ReadLine());
   WriteLine("Give me another number:");
   secondNumber = ToInt32(Console.ReadLine());
   WriteLine("Give me another number:");
   thirdNumber = ToInt32(ReadLine());
   WriteLine("Give me another number:");
   fourthNumber = ToInt32(ReadLine());
   WriteLine($"The product of {firstNumber}, {secondNumber}, " +
           $"{thirdNumber}, and {fourthNumber} is " +
           $"{firstNumber * secondNumber * thirdNumber * fourthNumber}.");
}

Note that Convert.ToInt32() is used here, which isn't covered in the chapter.

Chapter 4 Solutions

Exercise 1

(var1 > 10) ^ (var2 > 10)

Exercise 2

using static System.Console; using static System.Convert; static void Main(string[] args) { bool numbersOK = false; double var1, var2; var1 = 0; var2 = 0; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required