Variables and Data
- 5x = 10
- 5x = 15
- A temporary placeholder
- With computers, you have to define a variable before using it and include in that definition what kind of code it is, give it a name.
- Ex: Byte can hold a value
- between 0 and 255
bool 0 or 1 1 1
byte 0 to 255 8 1
decimal 29 digits 128 16
double double 64 8
int -2bill to 2 bill 32 4
long -/+ 9 sextillion 64 8
ulong 0 to 18 sextilliom 64 8
short -32thousand to 32" "16 2
- The difference between WriteLine and Write is that WriteLine adds a line in between like hitting the enter key
- the word String refers to text variables
- string step1String; is a variable declaration. You define what it is with the first part.the second part is the value
- The convert method will convert things from one
- Console.WriteLine("{0} plus {1} is {2}.", step1andstep2, step3, step1andstep2andstep3); FORMAT STRING
- a format string: a string of hcaracters that contains one or more placeholders.
- Placeholder: a number inside a pair of { }.
- the placeholder will be replaced by the value of the variable that is listed later in the statement
- Literal- can be saved as data type string or char
- A char variable stores weird characters
- A variable declaration is a way of telling the compiler these 2 things; data type that the variable will store name of the the variable
- int age;
- 2 Parts of declaring a variable
- Format string- is a placeholder for the variables in a string.
- Casting - (int) 6.7 + 1 = Must put 'int' for decimal in parentheses
- (int) (6.7 + 1)
- No more than 40 characters
- Can only use letters numbers and the underscore
- first character must be a letter. usually lower cased
- names must be meaningful
- Type Casting- you can type your own variable, not something the user types
- how to convert something
- yourNumber = Convert.ToInt32(yourString);