CSF1 Flashcards
How do you create a single line comment?
//
Where does a program START to RUN?
** the Main() method**
Why can’t you break a string into 2 lines?
C# ignores whitespace except inside a string
What should you do with code that does not work?
do NOT delete code that does NOT work; comment out code that does NOT work
What is a variable?
a container;
contents can be changed;
must use some date type
Since a data type cannot be changed programatically…that means what?
It’s TYPE SAFE
Define…
Declaration vs. Initialization vs. Assignment
- Declaring means creating it: datatype & name
- Initializing means giving it a value for the first time
- Assigning means giving it a value
What’s missing here?
int thereCanBe
What’s the difference between the two lines of code?
thereCanBe = 1;
thereCanBe = 2
thereCanBe = 1; is the initiailization of the variable
thereCanBe = 2; is reassignment of the variable
string jedi = “Luke Skywalker”;
** Console.WriteLine(jedi);**
int bigNbr;
bigNbr = 55321;
//declare
//initialization //don't use commas!! they are for hoomans.
What’s the difference here?
Console.WriteLine(bigNbr);
Console.WriteLine(55321);
Console.WriteLine(“55321”)
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
What’s the difference between a string and an int?
int deadGoblins = 57460;
int deadOrcs = 42540;
Console.WriteLine(“Orcs Killed: “ + deadOrcs);
Console.WriteLine(“Total Monsters Killed: “
\+ (deadGoblins + deadOrcs));
**What is contatenation? **
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
What are the rules to naming a variable?
- 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 {}
* */
What’s the difference?
if deadOrcs has already been declared and initialized
int deadOrcs = 43540;
** deadOrcs = 43540;**
**What are constants? **
they are variables that MUST be assigned when declared; the value cannot be reassigned
What does a constant variable look like?
constant datatype variableName = value
Do multiple variables, of the same datatype, have to be declared and initialized individually?
No, they can all be declared together…and initialized individually
What makes up a variable?
datatype variableName = value
it can be declared and initialized at the same time or declared then initialized later
How would declare multiple varialbes, but only initialize one variable?
int blasters, spears, lightsabers = 10;
only lightsabers was initialized
What’s happening here?
** int coaches = 2, players = 30, cheerleaders = 15;**
variables of the same type are being declared and initialized all at the same time
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”;
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
Console.WriteLine(“add 2 ints”);
Console.WriteLine(17 + 23);
********************************************
Console.WriteLine(“add 2 strings”);
Console.WriteLine(“17” + “23”);
How do you create a section in a cs file that can be collapsed/expanded?
#region
#enderegion
What are naming convetions?
Rules on how to name things
When is lowercase used?
lowercase
HAS TO BE USED with keywords
This convention is not used anywhere else
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.
What naming convetion is this?
btnClick
lblDisplay
Hungarian/Lezinski
button variable named Click
label name Display
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;**
What type of convention is used to name variables?
…Typically this is used for variables and parameters
camelCase
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
How is pascal case written?
PascalCase
* - Uses capitalized 1st letter for every “word”
When is PascalCase used?
Typically PascalCase is used for “everything else”:
* namespace, class, method, properties, etc.
Declare and initialize 10 different data types
Use at least:
* 1 string
* 1 integer type
* 1 floating point type
* 1 bool
* 1 char
What is a bool?
**true/false datatype **