C# 101 Flashcards

1
Q

What can I build with C#

A

A website, a console app, mobile, or AI

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you output a line of text in a Console App (with no variables)?

A

Console.WriteLine(“Hello World!”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What’s a Console App?

A

An command-line application that runs in the terminal window

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you declare a string Variable?

A

string aFriend = “Kendra”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How would you output “Hello ____” using a string variable for the text to go in the blank?

A

string aFriend = “Scott”;

Console.WriteLine($”Hello {aFriend}”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

At the end of each line you need a…

A

semicolon ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is String Interpolation? Give an example.

A

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}”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a String?

A

A group of characters strung together

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What character is really important when dealing with strings that contain variables?

A

The dollar sign ($), because it signals that the string to be output contains at least one variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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}]”);

A

** Hello World! **
[Hello World! ]
[ Hello World!]
[Hello World!]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an example of a String Method?

A

.TrimStart()

.Trim()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an example of a Property?

A

.Length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you run code in Visual Studio (hotkey)?

A

CTRL-F5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How would you declare the following variables?
int
double
decimal

A

int a = 3;
double b = 3.0;
decimal c = 3.0M;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the M in a decimal variable declaration represent?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How can you tell a Method from a Property in code?

A

A Method is followed by parentheses ()

A Property is not followed by parentheses

17
Q

The most common error I have made so far is…

A

Forgetting the semicolon;

18
Q

CTRL-Z will…

A

Undo

19
Q

Multi-line IF statements need….

A

Curly braces: { }

20
Q

To have VS format your code for you (indent, etc)…

A

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”

21
Q

The == symbol…

A

…tests for equality

22
Q

The && symbol…

A

Represents “and”.

It means both conditions must be true to execute the statement in the True branch.

23
Q

The || symbol…

A

Represents “or”.

If either condition is true, the statement in the True branch will be executed.

24
Q

using System;

What does this mean?

A

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.

25
Q

Namespace - what is it?

A

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
26
Q

What is a Class?

A

TBD

27
Q

static void Main(string[] args)

In this statement, what does “Main” mean?

A

The Main Method is is your first Method. It tells your computer that this is the entry point; this is where the program starts.

28
Q

static void Main(string[] args)

In this statement, what does “static” mean?

A

The Main method needs to be static (unchanging)

29
Q

static void Main(string[] args)

In this statement, what does “void” mean?

A

“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.

30
Q

static void Main(string[] args)

In this statement, what does “string[]args” mean?

A

“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.