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
Q

What’s wrong here?

int jedis = 25, name = “Anakin”;

How should this code be written?

A

variables of different types cannot be declared or initialized together

int jedis = 25;

string name = “Anakin”;

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

When creating a new cs file, that has a Main() method, what’s the first thing you should do?

A

//end Main

//end class

//end namespace

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

Console.WriteLine(“add 2 ints”);

Console.WriteLine(17 + 23);

********************************************

Console.WriteLine(“add 2 strings”);

Console.WriteLine(“17” + “23”);

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

How do you create a section in a cs file that can be collapsed/expanded?

A

#region

#enderegion

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

What are naming convetions?

A

Rules on how to name things

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

When is lowercase used?

lowercase

A

HAS TO BE USED with keywords

This convention is not used anywhere else

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

What is Hungarian or Lezinski convetion?

btnsomeVariable

A

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.

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

What naming convetion is this?

btnClick

lblDisplay

A

Hungarian/Lezinski

button variable named Click

label name Display

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

When is UPPERCASE naming used?

A
  • *UPPERCASE
    - Used rarely, most typically with constants to make them**
  • *stand out, use an _ for a space**

** const int ONE_RING = 1;**

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

What type of convention is used to name variables?

…Typically this is used for variables and parameters

A

camelCase

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

What naming convetion is this?

Uses lowercase letters for the first “word” in the variable
* name, and capitalized 1st letter for all “subsequent” words

A

camelCase

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

How is pascal case written?

A

PascalCase
* - Uses capitalized 1st letter for every “word”

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

When is PascalCase used?

A

Typically PascalCase is used for “everything else”:
* namespace, class, method, properties, etc.

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

Declare and initialize 10 different data types

Use at least:
* 1 string
* 1 integer type
* 1 floating point type
* 1 bool
* 1 char

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

What is a bool?

A

**true/false datatype **

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

How many bits in a byte?

A

8

41
Q

Describe a float datatype?

A

can NOT use actual fractions

float myDay = 1 / 2;

float myDay = .5;

above needs “F” suffix to create a literal type

42
Q

How many bits in a short?

A

16

43
Q

How many bits in an int?

A

32

44
Q

How many bits in a long?

A

64

45
Q

What’s going on here?

byte byteNbr;

byteNbr = 0;

byteNbr = 255;

A

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
Q

Write an output for your first and last name as…

a variable initialized

a string of text

A
47
Q

What is the value range for:

byte

short

int

long

A

8

16

32

64

48
Q

What are the floating points?

A

float

double

decimal

49
Q

What’s needed for a float value?

…a decimal value?

A

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
Q

What is this code and what datatype is it?

** isTheDoctor = true;**

A

a bool variable being initialized

51
Q

What does string concatenation do?

A

it adds multiple lines of string together when output

52
Q

How is char datatype different from int?

A

a char only accepts 1 character as a value and must be contained in single quotes ‘ ‘

char someVariable = ‘A’;

char symbol = “$”

53
Q

What can be in a string variable?

A

any number of characters in double quotes

…letters, numbers, symbols

54
Q

What is EXPLICIT CASTING?

A

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
Q

What’s happend here?

decimal dec1 = 4.3m;

** decimal dec2 = (decimal)4.3;**

A

**they are the same…explicitly cast a double to a decimal **

56
Q

What are the two main options for output to the console?

A

WriteLine() …adds a line break after the output

**Write() …does not add a line break **

57
Q

What’s the difference between

Write()

and

WriteLine()

A

Write() has no line break after the output

WriteLine() does have a line break

58
Q

What are 3 options for Input in the console?

A

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
Q

What do you do first when using a ReadLine()?

A

Explain to the user what to type

60
Q

What do you want to do with a ReadLine()?

A

capture the input in a variable

61
Q

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!"**
A
62
Q

What’s the input datatype for a ReadLine()?

A

string

63
Q

How do you change a ReadLine() input to something other than a string?

A

parsing…

parses the data into a different datatype

string greyHairString = Console.ReadLine();

int greyNbr = int.Parse(greyHairString);

64
Q

Write out examples of ReadLine()’s parsed into the following datatypes:

int

decimal

A
65
Q

How can you invoke the Pares() method for the following

byte

short

int

long

decimal

double

float

A

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
Q

What are the two ways to change the ReadLine() input string to another datatype

A

Parsing or Converting

67
Q

How do is a value converted?

A

Convert.To32()

68
Q

What are the relational operators?

A

> greater than

< less than

>= greater than or equal to

<= less than or equal to

69
Q

How is = and == used?

A

= is for assignments

== is to test equality

70
Q

What’s the operator for not equal?

A

!=

71
Q

How do you explore something in intellisens?

A

with a period

72
Q

What are the logical operators and what do they do?

A

&& is used for AND

|| is used for OR

…they compare two values

73
Q

What is the ToString()

A

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
Q

What are escape sequences?

A

**Special codes used INSIDE a string, which begins with **

****

75
Q

What does this do?

\n

A

adds a line break in an output string

76
Q

How do you show a verbatim string?

A

@ at the begin of the double quote

“Julia says

"”hello”” and that….”

77
Q

What does concatenation do?

A

combines strings with other objects…must use + symbol to put them together

78
Q

What are two ways to add a line break to the console window?

A

\n within a string

or an empty

Console.WriteLine();

79
Q

What are the characteristics of an Array?

A

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
Q

How many ways can an Array be created?

A

There is only one way

string[] dresser = new string[4]

the array has a length of 4

81
Q

How is an array initialized?

A

values are initialized individually

and in any order

variable[index] = new variable[length]

82
Q

How can an array’s values be used?

A

indicate the index # with the variable name

dress[3]

83
Q

Can arrays be used in calculations?

A

YES

84
Q

Write out a calculation with an array with the length of 5

A

**decimal totalSale = **

prices[0] + prices[1]…

85
Q

How do you put an array in an order?

A

Array.Sort(arrayname);

86
Q

What’s the difference…

.Sort()

**and **

.Revers()

A

Array.Sort is used to sort an array ascending

87
Q

How do you get a descending sort?

A

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
Q

Is there a short to sort an array in descending order?

A

No…you must first .Sort(), then .Reverse() the array

89
Q

What’s the shortcut to declare and initialize an array?

A

datatype[] variable = {value comma separated}

90
Q

When you declare and initialize an array what does .Net do?

A

it figures what the length should be

91
Q

Write a Console.WriteLine() using an array with a length of 5

A
92
Q

double[] lotsOfSomething = { 34, 45, something };

A
93
Q

double something = 12.5;

A
94
Q

Console.WriteLine(“The cows we have in the 3rd box is: “
+ cows[2]);

A
95
Q

int[] cows = { 0, 80, 20, 40, 15, 42, 99 };

A
96
Q

string[] dresser2 = {“socks”, “underwear”, “shirts”,
“shorts”};

A
97
Q

decimal totalSale =
(prices[0] + prices[1] + prices[2] + prices[3] + prices[4]);

A
98
Q
A