Liner Notes
Sample answers to "Check Yourself…" questions
When you buy an album on vinyl, the liner notes (or "jacket notes") are the information that’s printed on the back of the sleev or, for music on CD or cassette, in a booklet inside the plastic case. Basic liner notes are just the song titles, and the names of the artists and producers. But sometimes you get lucky, and the liner notes have blurbs written by the artists, or maybe even the complete lyrics to the songs. In other words, a cheat sheet that really helps you understand the music.
These liner notes have answers and basic explanations to the Check Yourself… questions from the chapters. These aren’t meant to be comprehensive answers, just a little information so you can confirm you’re…well, I hate to say it, but…on the right track.
The review questions are intended to be a little open-ended, so your answers will vary from these.
Getting Started Chapter
-
What tools do you need to develop C# programs?
You’ll need an IDE and the .NET SDK.
-
What does IDE stand for and what is it’s role in software development?
IDE stands for Integrated Development Environment. It’s the software you’ll use to write your C# code.
-
What IDE did you choose? Why?
Anything is fine, as long as it supports C#! Popular choices include Visual Studio Community, Visual Studio Code, and JetBrains Rider.
1. Computers and Coding
-
What is the primary role of a programming language in the context of computer programming?
The primary role of a programming language is to act as a bridge between human language and machine language. It allows humans to write instructions in a way that is easier for them to understand and use, which can then be accurately translated into machine language that a computer can execute.
-
What happens when you run a C# program? Describe that process in simple terms.
When you run a C# program, your code gets compiled (translated) into something the computer can understand, then the computer follows your instructions step by step and shows the results (like printing text or doing math).
-
What’s the difference between Console.Write() and Console.WriteLine()? When would you use each?
Console.Write() prints text and keeps the cursor on the same line. Console.WriteLine() prints text and moves the cursor to a new line. Use Write() when you want output to continue on the same line, and WriteLine() when you want it to start a new line afterward.
-
How would you explain what a “program” is to an 8-year-old?
A program is like a list of instructions you give to a computer—kind of like a recipe. The computer follows the steps exactly to do something, like showing a message or solving a puzzle.
-
Explain the difference between compiled and interpreted programming languages. Describe how C# is both compiled *and interpreted.*
-
Compiled languages are those where the source code is translated into machine language by a compiler before the program is run. This machine language file can then be executed directly by the computer. An example of a compiled language is C.
-
Interpreted languages are those where the source code is translated into machine language on the fly, as the program is running, by an interpreter. An example of an interpreted language is Python.
-
C# is a somewhat unique case, as it is both compiled and interpreted. The source code is first compiled into an intermediate language called CIL, which is then interpreted by the .NET runtime (CLR) when the program is executed. This allows C# to have some of the performance benefits of compiled languages while still being able to run on different platforms.
-
2. Variables and Data Types
-
What is a variable, and why do we use them in programming?
A variable is a named storage location in a program that holds a value which can change as the program runs. We use variables to store, update, and reuse data.
-
Which C# data type would you use for each of the following?
-
The number of people in The Beatles →
int
-
The full name of the Beatles bass player →
string
-
Whether the Beatles are a great band (yes or no) →
bool
-
The price of Sgt. Pepper’s Lonely Hearts Club Band on vinyl →
double
-
John Lennon’s middle initial (it’s W, incidentally) →
char
-
-
Write a line of code that declares a variable named importantYear and sets it to 1964.
int importantYear = 1964;
-
What will the following code print? Why?
1 2 3
string drummer = "Pete Best"; drummer = "Ringo Starr"; Console.WriteLine(drummer);
The code will print "Ringo Starr" because the variable
drummer
is first set to "Pete Best" and then changed to "Ringo Starr". The most recent value assigned to the variable is what gets printed. -
What happens if you try to store a word (like "hello") in a variable declared as int?
The program will not compile. You can’t assign a value of one data type to a variable of another (incompatible) data type. You also can’t change the data type of a variable after you’ve declared it.
-
What’s wrong with this variable name:
4ladsFromLiverpool
?A C# variable name can’t start with a number. You could call it
fourLadsFromLiverpool
instead. -
True or False: You must always assign a value to a variable at the same time you declare it
False. You can declare a variable and assign a value to it later:
1 2
int albums; albums = 12;
-
What are compound assignment operators in C#? Provide examples of how they are used in arithmetic operations.
Compound assignment operators combine an arithmetic operation with assignment. Examples:
1 2
int numBeatles = 5; numBeatles -= 1; // Rest in peace, Stuart Sutcliffe!
-
Write a short program that asks for the user’s name and the number of Beatles albums they own, and then prints a personalized message like: “Hello Stu, you have 5 Beatles albums.”
BeatlesGreeting.cs
1 2 3 4 5 6 7
Console.Write("What is your name? "); string name = Console.ReadLine(); Console.Write("How many Beatles albums do you own? "); int albums = Convert.ToInt32(Console.ReadLine()); Console.WriteLine($"Hello {name}, you have {albums} Beatles albums.");
-
10. What are the two ways to convert a
string
to a numeric type, such asint
ordouble
? Show the syntax of each.You can convert a string to a numeric type using either the
Convert
class or theParse
method. Here are examples of both:1 2 3
string nineteenSixtyNine = "1969"; int woodstockYear = Convert.ToInt32(nineteenSixtyNine); // Using Convert class woodstockYear = int.Parse(nineteenSixtyNine); // Using Parse method
3. Methods
-
What is a method, and why would you use one in your code?
A method is a named block of code that does something — like a mini-program inside your program. You use methods to organize your code, avoid repetition, and make your program easier to understand and manage. (Like reusable LEGO chunks.)
-
What’s the difference between calling a method and defining a method?
Defining a method is writing what the method does. Calling a method is telling it to actually run. You define once, but can call it as many times as you want.
-
What does the keyword
void
mean in a method definition?void
means the method doesn’t return anything. It just does something, like printing text, but doesn’t give a value back. -
Consider the code below. a. What does it do? b. How would you call it to greet someone named "Brian Epstein"?
1 2 3 4
static void Greet(string name) { Console.WriteLine($"Hello, {name}!"); }
-
It prints a greeting using the name you give it.
-
Greet("Brian Epstein");
-
-
Consider the code below. a. What would the method return? b. How would you use that returned value?
1 2 3 4
static int AddTwoNumbers(int a, int b) { return a + b; }
-
It adds the two numbers and returns the result. So
AddTwoNumbers(2, 3)
would return 5. -
For example, you could store the result in a variable:
int total = AddTwoNumbers(4, 6);
-
-
Consider the code below. a. Overload the method by accepting the name of a band to introduce. b. Demonstrate how to call each version of the method.
1 2 3 4
static void AnnounceBand() { Console.WriteLine("Ladies and gentlemen, The Beatles!"); }
-
Overloaded method:
1 2 3 4
static void AnnounceBand(string bandName) { Console.WriteLine($"Ladies and gentlemen, {bandName}!"); }
-
Calling each version:
1 2
AnnounceBand(); // Calls the original method AnnounceBand("The Rolling Stones"); // Calls the overloaded method
-
4. Decisions
-
Q1
Answer
5. Loops
-
Q1
Answer
6. Debugging and Generative AI
-
Q1
Answer
7. Classes and Objects
-
Q1
Answer
8. Arrays
-
Q1
Answer
9. Software Development Life Cycle
-
Q1
Answer
10. Graphical User Interfaces
-
Q1
Answer
B-Side: Lo-Fi Testing
-
What are the two main parts of a test case, and why is it important to define them before you start writing code?
A test case includes inputs (the data the program uses) and the expected output (the result the program should produce). Defining test cases before coding helps you understand the problem better and plan how your program will work, instead of just jumping in and hoping it all comes together.
-
Why is it not enough to test your program with just one set of inputs? Give an example of an “edge case” that might catch a bug.
One test case might only show that your code works in that specific situation. To be sure your program works in general, you need to test it with a variety of inputs, including unusual or tricky ones.
An example of an edge case: If you’re writing a program that determines if a person is old enough to vote, the input 17 should return "no"; 18 should return "yes".
-
How can writing your test cases early help you figure out what variables or calculations your program will need?
Thinking through test cases makes you figure out the steps to solve the problem. It helps you see what data you need, what formulas you’ll use, and what your program should do at each stage. It’s like using the test cases to reverse-engineer your program before you even start coding.