Before we read the contents of the CSV files (which we created in Step 12) into our app, there are a couple of things we need to do in preparation for that.
First, add a variable to the Form1.cs file like so:
string CSVPath = @“C:\Programming4Kids\”;
We will access, or refer to, this variable (CSVPath) when we read the files from that folder.
Note: You probably noticed the “at” symbol in the line of code above where the variable CSVPath is declared and asked it, “What are you doing there, at symbol?” perhaps in a bewildered tone -- or possibly even in a slightly exasperated one. That “at” symbol (@) actually saves us a lot of trouble when dealing with strings which contain backslashes (such as paths to folders and files). It informs the compiler to take what follows in the string (everything within the quotation marks) literally. “Why wouldn’t it take it literally in the first place?” you might wonder. Well, normally back slashes have to be doubled, or “escaped” before the compiler knows how to handle them. Using “@” allows us to simply insert the path, backslashes and all, inside the string without worrying about doing that (that is, doubling the back slashes to clarify our intent). We will escape further explanation of “escaping” for now, though. It’s a rather dry and dull subject. All you need to know for now is that if you use the “at” symbol (@), you are okay that way.
The next thing we need to do in preparation for reading in the contents of the CSV files is to create a Class in which to store the records. A class? What sort of class? Are we talking about a class as in school – a room, or a group of students? No. Are we talking about class in the sense of “That cat has a lot of class – he even dresses up to brush his teeth”? Or, “She has a ton of class – she dresses to the Nines when Sixes and Sevens would do!” No. This is a Class of a different stripe.
Speaking of stripes and class, how about this cat:

Siberian Tiger photo by S. Taheri, edited by Fir0002 / CC BY-SA (https://creativecommons.org/licenses/by-sa/2.5)
In programming lingo, a Class is a named structure that contains “members.” So now we have to briefly talk about members. Actually, the word makes it pretty self-explanatory, but an example will probably make it plain. Here’s the Class we will add to contain the contents of the files we will be programmatically reading:
public class MultipleChoiceClass
{
public string Question;
public string CandidateAnswer1;
public string CandidateAnswer2;
public string CandidateAnswer3;
public int CorrectAnswer = 0;
}
To do this, follow these steps:
1) In the upper right of Visual Studio, right-click your Project (GuessingAges) and select Add > Class. Most of what you will select is rectangled in the screen shot below:

That will open the “Add New Item” window:

2) Change the default generic name “Class1.cs” (automatically highlighted at the bottom) to “MultipleChoiceClass.cs”
3) In the file that opens, locate this bit of code:
class MultipleChoiceClass
{
}
4) Add this between the curly braces:
public string Question;
public string CandidateAnswer1;
public string CandidateAnswer2;
public string CandidateAnswer3;
public int CorrectAnswer = 0;
...so that it looks like the code snippet shown earlier.
What we have here is a Class which is designed to hold a line of data from the CSV file. You might refer to this group of data as a “record.” Calling a group of related information a “record” is common database terminology. This is not strictly speaking a database, though – the true database stuff comes later.
Note: Pet peeve alert! I am going to go on a bit of a rant and whine (or “whinge,” if you prefer the British flavour of English) about the pronunciation of the word spelled “d-a-t-a-b-a-s-e.” Some people – even those who should know better – pronounce it as if it has two “T”s in it, pronouncing the first “a” as a short vowel; but the word only has one “T,” so both instances of the letter “a” in the word should be pronounced as long vowels. So it’s DAY-tuh-base, not Dat’uh-base.
Any time you add new code, you should rebuild, or compile, your project again to make sure that everything is working as it should. If you wait too long between checking the validity of your code, you may end up with a lot of problems to fix and it could get confusing. So get in the habit of simultaneously selecting Ctrl+Shift+B (holding down all those keys at the same time) OR selecting Build > Build Solution from Visual Studio’s menu bar. It is always gratifying (and a bit of a relief) when your code compiles (the app builds without errors). How do you know all is good with your code? After building it, you should get a message at the bottom of Visual Studio that says, “Build: 1 succeeded, 0 failed” as you see rectangled below:

Who, Ray? No – Hooray! 0 failed! 0 is good. 0 is great! I told you 0 was an actual integer. And a very handy one. Where would we be without zeroes? If we were ancient Romans, we would write “100” as “C” and “1,000” as “M” and 10,000 as “X” – horrible! What rhyme or reason is there in that?!? It’s a good thing the East Indians invented the 0.
Sometimes a project will compile without errors, but still have warnings. The problem could be that members of a Class have not been assigned default values. If so, they have green squiggly lines under them, giving us a clue that they feel a bit sickly. Actually, the code would still run, as these are “just” warnings and not errors, but it’s best to also eliminate all warnings as they crop up. You can eliminate such warnings by assigning the members default values, like so (this prevents the Warnings in our case):
public string Question = string.Empty;
public string CandidateAnswer1 = string.Empty;
public string CandidateAnswer2 = string.Empty;
public string CandidateAnswer3 = string.Empty;
public int CorrectAnswer = 0;
Now when we re-build the app, the code is “perfect”: there are no errors and no warnings:

So: heave a sigh of relief, pat yourself on the back, and take a look at MultipleChoiceClass. As you can see, it is designed to store the Question and the three Candidate Answers. Also, an int member, CorrectAnswer, is part of the Class. CorrectAnswer will store which of the three Candidate Answers is the correct one (based on which one is prepended with the “*”). In other words, if CandidateAnswer1 is the correct answer, the CorrectAnswer Class member will be assigned the value 1. If CandidateAnswer2 is the correct answer, the value of the CorrectAnswer Class member will be 2, and the same pattern will be the case for CandidateAnswer3.
Another way you can look at it is this: the Class is a pattern, and the instances of it are the garments made from the pattern. Or, the Class is a recipe for cookies, and the instances of it are the individual cookies that the recipe allows you to bake. Something like that. You can come up with your own illustration; you should, in fact, at least try to do so. Here are some cookies (instances of a recipe):

Picture of Chocolate Chip Cookies by Rdsmith4 / CC BY-SA (https://creativecommons.org/licenses/by-sa/2.5)
The cookie analogy is actually a pretty good one, because the recipe is like a description (which is what the Class declaration is), and the cookies are the actual things “come to life,” as it were (they are the “instances” of the class, filled with actual data). And the cookies are all basically the same, exhibiting the same properties or qualities, but they are also all unique, in that they are of slightly different sizes, with varying distributions of chocolate chips (where they are located, and how many there are). And so it is with the instances of the Class – they have the same members, but the exact data assigned to those members differs from instance to instance.
In the next Step, we will (programmatically) read the files and save their contents in our app.
You can listen to the audio version of this Step here: