C# 101 Flashcards
What can I build with C#
A website, a console app, mobile, or AI
How do you output a line of text in a Console App (with no variables)?
Console.WriteLine(“Hello World!”);
What’s a Console App?
An command-line application that runs in the terminal window
How do you declare a string Variable?
string aFriend = “Kendra”
How would you output “Hello ____” using a string variable for the text to go in the blank?
string aFriend = “Scott”;
Console.WriteLine($”Hello {aFriend}”);
At the end of each line you need a…
semicolon ;
What is String Interpolation? Give an example.
Placing a variable between { and } characters to tell C# to replace that text with the value of the variable. Example:
string aFriend = “Scott”;
Console.WriteLine($”Hello {Scott}”);
What is a String?
A group of characters strung together
What character is really important when dealing with strings that contain variables?
The dollar sign ($), because it signals that the string to be output contains at least one variable.
What will the output look like?
string greeting = “ Hello World! “;
Console.WriteLine($”{greeting}”);
string trimmedGreeting = greeting.TrimStart();
Console.WriteLine($”[{trimmedGreeting}]”);
trimmedGreeting = greeting.TrimEnd();
Console.WriteLine($”[{trimmedGreeting}]”);
trimmedGreeting = greeting.Trim();
Console.WriteLine($”[{trimmedGreeting}]”);
** Hello World! **
[Hello World! ]
[ Hello World!]
[Hello World!]
What is an example of a String Method?
.TrimStart()
.Trim()
What is an example of a Property?
.Length
How do you run code in Visual Studio (hotkey)?
CTRL-F5
How would you declare the following variables?
int
double
decimal
int a = 3;
double b = 3.0;
decimal c = 3.0M;
What does the M in a decimal variable declaration represent?
The letter M was chosen as a visually-distinctive way to distinguish a decimal type from a double type.
I like to think of it as “deciMal”.
How can you tell a Method from a Property in code?
A Method is followed by parentheses ()
A Property is not followed by parentheses
The most common error I have made so far is…
Forgetting the semicolon;
CTRL-Z will…
Undo
Multi-line IF statements need….
Curly braces: { }
To have VS format your code for you (indent, etc)…
First, Build the Solution, then run Code Cleanup
(was Format Document)
To do this, to to the bottom of the main window and click the dustbrush icon next to “no issues found”
The == symbol…
…tests for equality
The && symbol…
Represents “and”.
It means both conditions must be true to execute the statement in the True branch.
The || symbol…
Represents “or”.
If either condition is true, the statement in the True branch will be executed.
using System;
What does this mean?
The “using” statement imports a Library. This means that we have imported the System Library.
Console uses the System Library.
If you type “System.” you will see Methods and Properties appear after the dot. They are all part of the System Library.
Namespace - what is it?
An envelope or package that is used to group and organize related Classes.
There are namespaces that already exist, and you can create your own namespaces.
- Built-In Namespace
- Global Namespace
- ** Local Namespace
What is a Class?
TBD
static void Main(string[] args)
In this statement, what does “Main” mean?
The Main Method is is your first Method. It tells your computer that this is the entry point; this is where the program starts.
static void Main(string[] args)
In this statement, what does “static” mean?
The Main method needs to be static (unchanging)
static void Main(string[] args)
In this statement, what does “void” mean?
“void” indicates that the method returns nothing. All Methods in C# have to return something, so we use the term “void” to say that it returns nothing.
static void Main(string[] args)
In this statement, what does “string[]args” mean?
“string[]” represents an unlimited array of arguments. The brackets represent an array. This tells the program to take these arguments and do something with them.