Core Programming Flashcards
(33 cards)
int
4 bytes / 32 bits
can store whole numbers only
from -2,147,483,648 to 2,147,483,647.
It is the preferred data type when we create variables with a numeric value.
long
8 bytes / 64 bits
can only store whole numbers
from
-9(Quintillion),223(Quadrillion),372(Trillion),036(Billion),854,775,808 to 9223372036854775807.
This is used when int is not large enough to store the value. Note that you should end the value with an “L”:
float
signed 4 bytes / 32 bits
Stores fractional numbers.
Sufficient for storing 6 to 7 decimal digits
The float data type can store fractional numbers from 3.4e−038 to 3.4e+038. Note that you should end the value with an “F”:
double
signed 8 bytes / 64 bits
Stores fractional numbers.
Sufficient for storing 15 decimal digits
bool
1 bit Stores true or false values
char
2 bytes / 16 bits
Stores a single character/letter, surrounded by single quotes
string
2 bytes / 16 bits per character Stores a sequence of characters, surrounded by double quotes
decimal
signed 16 bytes / 128 bits
Stores a fractional number
up to 28-29 digits
Should end in M - decimal price = 1.50M;
To minimize the amount of storage used on the hard drive by an application that generates many small files, you should make the ______ as small as possible.
a - partition
b - file allocation table
c - block size
d - folder and file names
block size
byte
unsigned 8 BIT / 1 byte
0 to 255
Define Integer type (Integral)
Numbers that are whole numbers without decimal points. It can be negative or positive numbers.
Define Floating-point type
Floating-point type is numbers with one or more decimal points. It can be negative or positive numbers.
sbyte
signed 8 BIT / 1 byte
-128 to 127
short
It occupies 2 bytes / 16-bit memory.
The short data type is a signed integer that can store numbers from -32,768 to 32,767.
Signed vs unsigned values
signed means specified as positive or negative, unsigned means positive by default
Converting a value type to a reference type in an object is called BOXING.
Select the correct answer if the text in italics does not make the statement correct.
a - no change
b - unboxing
c - upcasting
d - downcasting
A - No change
changing a value type to a reference type = boxing
Value Type
A variable of a value type contains an instance of the type.
It is stored in the stack with both its name and value in the same entry.
Reference Type
contains a reference to an instance of the type (in heap memory)
An example is a string. The NAME of the variable is stored in the stack, which points to its memory address in the heap.
Upcasting
Upcasting is an operation that creates a base class reference from a subclass reference. (subclass -> superclass)
(i.e. Manager -> Employee)
Example:
Employee emp = (Employee)mgr; //mgr is Manager
Downcasting
Downcasting is an operation that creates a subclass reference from a base class reference. (superclass -> subclass) (i.e. Employee -> Manager)
Example:
if (employee is Manager)
{
Manager m = (Manager)employee;
}
GUID
Represents a globally unique identifier (GUID). A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required. Such an identifier has a very low probability of being duplicated.
for loop
When you know exactly how many times you want to loop through a block of code, use the for loop instead of a while loop.
for (int i = 0; i < 5; i++)
{
Console.WriteLine(i);
}
Statement 1 sets a variable before the loop starts (int i = 0).
Statement 2 defines the condition for the loop to run (i must be less than 5). If the condition is true, the loop will start over again, if it is false, the loop will end.
Statement 3 increases a value (i++) each time the code block in the loop has been executed.
foreach loop
used exclusively to loop through elements in an array:
string[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; foreach (string i in cars) { Console.WriteLine(i); }
while loop
The while loop loops through a block of code as long as a specified condition is True
int i = 0; while (i < 5) { Console.WriteLine(i); i++; }