1/24
Looks like no tags are added yet.
variables
container for storing data values
int
stores whole numbers w/o decimals
double
stores floating point numbers, with decimals,
char
stores single characters, surrounded by ‘single quotes’
string
stores text, surrounded by “double quotes”
bool
stores values with two states: true or false
const
unchangeable and read only, to not overwrite existing values
WriteLine()
this method is often used to display variable values to the console window
comma-separated list
used To declare more than one variable of the same type,
indentifiers
All C# variables must be identified with unique names.
These unique names are called
short names
identifiers like x and y
descriptive names
identifiers like age, sum, totalVolume
this is recommended to use in order to create understandable and maintainable code
can contain letters, digits, and underscores
must begin with a letter or underscore
should start with lowercase letter and cannot contain whitespace
case sensitive
reserved words cannot be used as names
general rules for naming variables
data type
specifies the size and type of variable values.
use the correct data type for the corresponding variable; to avoid
errors, to save time and memory,
will also make your code more maintainable
and readable.
long
like int, but can store whole numbers from -9 quintillion to 9 quintillion
float
stores fractional numbers, sufficient for storing 6-7 decimal digits
double
stores fractional numbers, sufficient for storing 15 decimal digits
preferred
integer and floating point
number types are divided into two groups
integer types
stores whole numbers, positive or negative (such as 123 or -456),
without decimals. Valid types are int and long. Which type you should use, depends
on the numeric value.
floating point types
represents numbers with a fractional part, containing one or more decimals. Valid types are float and double.
scientific numbers
A floating-point number can also be a scientific number with an "e" to indicate the power of 10:
type casting
is when you assign a value of one data type to another type.
implicit casting
converting a smaller type to a larger type size
char -> int -> long -> float -> double
explicit casting
converting a larger type to a smaller size type
double -> float -> long -> int -> char
Console.ReadLine()
to get user input
can be used too get input directly as a string