CSF1 Flashcards

1
Q

How do you create a single line comment?

A

//

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

Where does a program START to RUN?

A

** the Main() method**

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

Why can’t you break a string into 2 lines?

A

C# ignores whitespace except inside a string

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

What should you do with code that does not work?

A

do NOT delete code that does NOT work; comment out code that does NOT work

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

What is a variable?

A

a container;

contents can be changed;

must use some date type

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

Since a data type cannot be changed programatically…that means what?

A

It’s TYPE SAFE

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

Define…

Declaration vs. Initialization vs. Assignment

A

- Declaring means creating it: datatype & name

- Initializing means giving it a value for the first time

- Assigning means giving it a value

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

What’s missing here?

int thereCanBe

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

What’s the difference between the two lines of code?

thereCanBe = 1;

thereCanBe = 2

A

thereCanBe = 1; is the initiailization of the variable

thereCanBe = 2; is reassignment of the variable

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

string jedi = “Luke Skywalker”;

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

** Console.WriteLine(jedi);**

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

int bigNbr;

bigNbr = 55321;

A

//declare

//initialization
             //don't use commas!! they are for hoomans.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What’s the difference here?

Console.WriteLine(bigNbr);
Console.WriteLine(55321);
Console.WriteLine(“55321”)

A

ConsoleWriteLine() is an output to the screen

Line 1: is output the content of the varialbe

Line 2: is outputing a literal number

Line 3: is output as a string…the letters that look like numbers

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

What’s the difference between a string and an int?

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

int deadGoblins = 57460;

int deadOrcs = 42540;

Console.WriteLine(“Orcs Killed: “ + deadOrcs);

Console.WriteLine(“Total Monsters Killed: “

 \+ (deadGoblins + deadOrcs));
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

**What is contatenation? **

A

adding strings and objects together (b/c everything is an object)

the () around the numeric calcuation trumps the order

of operations and makes sure the concatenation happens AFTER the calculation

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

What are the rules to naming a variable?

A

- can only begin with alpha characters
*or underscores _

-After the first character you can use alpha, numberic, or underscore

- CANNOT contain spaces.

- MUST contain at least 1 alpha or numeric

- CANNOT be a C# reserved keyword (pg.19)

-MUST be unique within its scope {}
* */

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

What’s the difference?

if deadOrcs has already been declared and initialized

int deadOrcs = 43540;

** deadOrcs = 43540;**

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

**What are constants? **

A

they are variables that MUST be assigned when declared; the value cannot be reassigned

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

What does a constant variable look like?

A

constant datatype variableName = value

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

Do multiple variables, of the same datatype, have to be declared and initialized individually?

A

No, they can all be declared together…and initialized individually

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

What makes up a variable?

A

datatype variableName = value

it can be declared and initialized at the same time or declared then initialized later

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

How would declare multiple varialbes, but only initialize one variable?

A

int blasters, spears, lightsabers = 10;

only lightsabers was initialized

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

What’s happening here?

** int coaches = 2, players = 30, cheerleaders = 15;**

A

variables of the same type are being declared and initialized all at the same time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
**What's wrong here?** **int jedis = 25, name = "Anakin";** **How should this code be written?**
**variables of different types cannot be declared or initialized together** **int jedis = 25;** **string name = "Anakin";**
26
**When creating a new cs file, that has a Main() method, what's the first thing you should do?**
**//end Main** **//end class** **//end namespace**
27
**Console.WriteLine("add 2 ints");** **Console.WriteLine(17 + 23);** \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* **Console.WriteLine("add 2 strings");** **Console.WriteLine("17" + "23");**
28
**How do you create a section in a cs file that can be collapsed/expanded?**
**#region** **#enderegion**
29
**What are naming convetions?**
**Rules on how to name things**
30
**When is lowercase used?** **lowercase**
**HAS TO BE USED with keywords** **This convention is not used anywhere else**
31
**What is Hungarian or Lezinski convetion?** **btnsomeVariable**
**ses a lowercase prefix for the first few letters before \* the variable name starts. All "words" in a name after the \* prefix have capitalized 1st letter.**
32
**What naming convetion is this?** **btnClick** **lblDisplay**
**Hungarian/Lezinski** **button variable named Click** **label name Display**
33
**When is UPPERCASE naming used?**
* *UPPERCASE - Used rarely, most typically with constants to make them** * *stand out, use an _ for a space** ** const int ONE\_RING = 1;**
34
**What type of convention is used to name variables?** **...Typically this is used for variables and parameters**
**camelCase**
35
**What naming convetion is this?** **Uses lowercase letters for the first "word" in the variable \* name, and capitalized 1st letter for all "subsequent" words**
**camelCase**
36
**How is pascal case written?**
**PascalCase \* - Uses capitalized 1st letter for every "word"**
37
**When is PascalCase used?**
**Typically PascalCase is used for "everything else": \* namespace, class, method, properties, etc.**
38
**Declare and initialize 10 different data types** **Use at least: \* 1 string \* 1 integer type \* 1 floating point type \* 1 bool \* 1 char**
39
**What is a bool?**
**true/false datatype **
40
**How many bits in a byte?**
**8**
41
**Describe a float datatype?**
**can NOT use actual fractions** **float myDay = 1 / 2;** **float myDay = .5;** **above needs "F" suffix to create a literal type**
42
**How many bits in a short?**
**16**
43
**How many bits in an int?**
**32**
44
**How many bits in a long?**
**64**
45
**What's going on here?** **byte byteNbr;** **byteNbr = 0;** **byteNbr = 255;**
**Line 1: the variable byteNbr is a byte datatype and is being declared** **Line 2: the variable is being initialized** **Line 3: the variable is being reassigned**
46
**Write an output for your first and last name as...** **a variable initialized** **a string of text**
47
**What is the value range for:** **byte** **short** **int** **long**
**8** **16** **32** **64**
48
**What are the floating points?**
**float** **double** **decimal**
49
**What's needed for a float value?** **...a decimal value?**
**float requires f or F at the end of the value to fix the decimal point** **decimal requires m or M at the end of the value; decimal is used for money**
50
**What is this code and what datatype is it?** ** isTheDoctor = true;**
**a bool variable being initialized**
51
**What does string concatenation do?**
**it adds multiple lines of string together when output**
52
**How is char datatype different from int?**
**a char only accepts 1 character as a value and must be contained in single quotes ' '** **char someVariable = 'A';** **char symbol = "$"**
53
**What can be in a string variable?**
**any number of characters in double quotes** **...letters, numbers, symbols**
54
**What is EXPLICIT CASTING?**
**going from a larger to a smaller container requires extra work.** **You have to explicitly state the data you're casting to. Can be messy if the value won't fit.**
55
**What's happend here?** **decimal dec1 = 4.3m;** ** decimal dec2 = (decimal)4.3;**
**they are the same...explicitly cast a double to a decimal **
56
**What are the two main options for output to the console?**
**WriteLine() ...adds a line break after the output** **Write() ...does not add a line break **
57
**What's the difference between** **Write()** **and** **WriteLine()**
**Write() has no line break after the output** **WriteLine() does have a line break**
58
**What are 3 options for Input in the console?**
**Read() -- only takes 1 keystroke of input.** **ReadyKey() -- Similar idea (the book uses this to halt there programs)** **ReadLine() -- Most common to be used, it allows the user to input something, and reads the user's input AFTER they hit enter.**
59
**What do you do first when using a ReadLine()?**
**Explain to the user what to type**
60
**What do you want to do with a ReadLine()?**
**capture the input in a variable**
61
**Mini Lab:** **//ask the user for their favorite color** ``` ** //and then tell them the color back and what //you think of it, for example //"COLOR is great!"** ```
62
**What's the input datatype for a ReadLine()?**
**string**
63
**How do you change a ReadLine() input to something other than a string?**
**parsing...** **parses the data into a different datatype** **string greyHairString = Console.ReadLine();** **int greyNbr = int.Parse(greyHairString);**
64
**Write out examples of ReadLine()'s parsed into the following datatypes:** **int** **decimal**
65
How can you invoke the Pares() method for the following byte short int long decimal double float
**byte.Parse() or Byte.Parse() \* short.Parse() or Int16.Parse() \* int.Parse() or Int32.Parse() \* long.Parse() or Int64.Parse() \* decimal.Parse() or Decimal.Parse() \* double.Parse() or Double.Parse() \* float.Parse() or Single.Parse**
66
**What are the two ways to change the ReadLine() input string to another datatype**
**Parsing or Converting**
67
**How do is a value converted?**
**Convert.To32()**
68
**What are the relational operators?**
**\> greater than** **\< less than** **\>= greater than or equal to** **\<= less than or equal to**
69
**How is = and == used?**
**= is for assignments** **== is to test equality**
70
**What's the operator for not equal?**
**!=**
71
**How do you explore something in intellisens?**
**with a period**
72
**What are the logical operators and what do they do?**
**&& is used for AND** **|| is used for OR** **...they compare two values**
73
**What is the ToString()**
**a method to get the string version of any variable of any datatype** **"Call" this method after the variable** **decimal someDecimal = 1253.6542m; string nbrString = someDecimal.ToString();**
74
**What are escape sequences?**
**Special codes used INSIDE a string, which begins with ** **\**
75
**What does this do?** **\n**
**adds a line break in an output string**
76
**How do you show a verbatim string?**
**@ at the begin of the double quote** **"Julia says** **""hello"" and that...."**
77
**What does concatenation do?**
**combines strings with other objects...must use + symbol to put them together**
78
**What are two ways to add a line break to the console window?**
**\n within a string** **or an empty** **Console.WriteLine();**
79
**What are the characteristics of an Array?**
**have a set size (cant be change programatically)** **the size is calld the length (1-based counting)** **type safe** **use the new keyword to construct** **indexes are 0-based counting**
80
**How many ways can an Array be created?**
**There is only one way** **string[] dresser = new string[4]** **the array has a length of 4**
81
**How is an array initialized?**
**values are initialized individually** **and in any order** **variable[index] = new variable[length]**
82
**How can an array's values be used?**
**indicate the index # with the variable name** **dress[3]**
83
**Can arrays be used in calculations?**
**YES**
84
**Write out a calculation with an array with the length of 5**
**decimal totalSale = ** **prices[0] + prices[1]...**
85
**How do you put an array in an order?**
**Array.Sort(arrayname);**
86
**What's the difference...** **.Sort()** **and ** **.Revers()**
**Array.Sort is used to sort an array ascending**
87
**How do you get a descending sort?**
**First, you must .Sort() the array, then Array.Reverse() to make descending;** **if you only use .Reverse...it only flips the contents of the array**
88
**Is there a short to sort an array in descending order?**
**No...you must first .Sort(), then .Reverse() the array**
89
**What's the shortcut to declare and initialize an array?**
**datatype[] variable = {value comma separated}**
90
**When you declare and initialize an array what does .Net do?**
**it figures what the length should be**
91
**Write a Console.WriteLine() using an array with a length of 5**
92
double[] lotsOfSomething = { 34, 45, something };
93
double something = 12.5;
94
Console.WriteLine("The cows we have in the 3rd box is: " + cows[2]);
95
int[] cows = { 0, 80, 20, 40, 15, 42, 99 };
96
string[] dresser2 = {"socks", "underwear", "shirts", "shorts"};
97
decimal totalSale = (prices[0] + prices[1] + prices[2] + prices[3] + prices[4]);
98