Practicing and exploring
Test your knowledge and understanding by answering some questions, get some hands-on practice, and explore the topics covered in this chapter with deeper research.
Exercise 2.1 – Test your knowledge
To get the best answer to some of these questions, you will need to do your own research. I want you to "think outside the book" so I have deliberately not provided all the answers in the book.
I want to encourage you to get in the good habit of looking for help elsewhere, following the principle of "teach a person to fish."
What type would you choose for the following "numbers"?
- A person's telephone number
- A person's height
- A person's age
- A person's salary
- A book's ISBN
- A book's price
- A book's shipping weight
- A country's population
- The number of stars in the universe
- The number of employees in each of the small or medium businesses in the United Kingdom (up to about 50,000 employees per business)
Exercise 2.2 – Practice number sizes and ranges
Create a console application project named Exercise02
that outputs the number of bytes in memory that each of the following number types uses, and the minimum and maximum values they can have: sbyte
, byte
, short
, ushort
, int
, uint
, long
, ulong
, float
, double
, and decimal
.
More Information: You can always read the documentation, available at https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting for Composite Formatting to learn how to align text in a console application.
The result of running your console application should look something like the following screenshot:
Figure 2.10: The result of the console application
Exercise 2.3 – Explore topics
Use the following links to read more about the topics covered in this chapter:
- C# Keywords: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/index
- Main() and command-line arguments (C# Programming Guide): https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/main-and-command-args/
- Types (C# Programming Guide): https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/
- Statements, Expressions, and Operators (C# Programming Guide): https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/
- Strings (C# Programming Guide): https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/strings/
- Nullable Types (C# Programming Guide): https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/nullable-types/
- Nullable reference types: https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references
- Console Class: https://docs.microsoft.com/en-us/dotnet/api/system.console