C# Basics Flashcards
What is the first word in a C# file?
The first word in the file is class.
All code is contained in a class.
How many classes can your program have?
As many as you need it to have.
How many classes are TYPICALLY in one file?
One.
If there is only one class in a file, what should you typically name the file?
The same thing that you named the class within the file.
What is a C# file extension?
.cs
What element is one step down in the hierarchy from a class that you use to further organize the code?
A method. You can add as many as you need.
What are the four basic parts of a method?
Name, body, parameters and type.
Name (of the methoid), body (inside curly braces - this is where you write the instructios), Parameters (info listed next to the method name in parenthesis - used when calling methods , tells other methods what info is needed if you use the method) AND finally TYPE. Tells what kind of info the method will return.
What is “calling a method”
You can make one of your methods use (or call upon) another method.
What are the three basic building blocks of a C# program?
(in order) Files, classes and methods.
How does the compiler know which code to run first in your program?
The file containing the class containing the method named “Main()”
All of the methods you write can be called whatever you want, but one has to be called Main.
Capital M
What is a keyword?
Keywords are special words that are reserved for the language itself.
This means that we can’t use them in names of things like classes and methods.
What are the 4 P’s of Problem Solving?
First, there’s preparation where we understand the problem and think of a solution.
Second, plan, where we plan out the solution.
Third, perform. Where we perform the actions required for our purposed solution.
And finally, fourth, we perfect the solution.
Perfecting doesn’t mean that the project that the project will be perfect
when we get to the end of the perfecting stage.
Which method in the .net framework can be used to print to the console?
System.Console.Write(“”);
Which method in the .net framework can be used to read from the console?
System.Console.ReadLine();
What this method does do is return what the user typed back to our program.
Variable:
A variable is a way to temporarily store information that our code can use.
First step in creating a variable:
Specifying the TYPE of info it needs to store. (e.g. string )
Second step in creating a variable:
Give it a name.
Variable names can contain letters, numbers, or an underscore character.
1:38
But they can’t start with a number.
1:39
The name should be descriptive of what it’s meant to store.
What is a variable assignment?
Taking a pre-existing declared variable and setting it equal to a value that agrees with its declared type.
What does Initializing a variable mean?
Declaring it and assigning in the same line.
aka - string firstName = “Ben”;
instead of
string firstName;
firstName = “Ben”;
Disect the following method from the .Net Framework: System.Console.Write
Write is the name of the method.
Console is the name of the CLASS that contains the METHOD “Write” within the framework.
System is the NAMESPACE within the framework. Classes are contained within namespaces.
What is the purpose of a namespace?
To make it so that we could potentially have multiple classes with the same name. Think of a namespace as the name of a town and the class is main street.
You cant just send a letter to mainstreet, you have to send it to main street in Grantsville.
Now, if there are multiple “mainstreet” classes in your program, the compiler can distinguish between the Classes “mainStreet” in the namespaces Grantsville and Tooele.
You can use more than one namespace and further organize your library of code.
How can you eliminate the use of specific namespaces throughout your file?
Include a “using directive”. Type “using” followed by the name of the namespace. You will then not have to type that out every time.
What does the System.Console.WriteLine method from the .Net Framework, do?
It prints text to the console and then brings the cursor to the next line.
This differs from theSystem.Console.Write method because the cursor remains on the same line once that method is called.
What is string concatenation?
Adding multiple strings together using the + symbol. (also called the concatenation operator.)
Console.WriteLine(“You’ve entered “ + entry + “ minutes.”);
What is a REPL?
Read Evaluate Print Loop