General Flashcards
What are the data types in C#?
int 32 bit
long 64 bit Note that you should end the value with an “L”
float 32 bit Note that you should end the value with an “F”
double 64 bit Note that you can end the value with a “D” (although not required)
bool 1 bit
char 16 bits surrounded by single quotes
string 16 bits per character
What is type casting?
Type casting is when you assign a value of one data type to another type.
What is implicit casting?
Implicit casting is converting a smaller type to a larger type size.
char>int>long>float>double
Can be done automatically.
int myInt = 9;
double myDouble = myInt;
What is explicit casting?
Explicit casting is converting a larger type to a smaller size type.
double>float>long>int>char
Must be done manually.
double myDouble = 9.78;
int myInt = (int) myDouble;
What are the methods to explicitly convert a data type?
Convert.ToBoolean, Convert.ToDouble, Convert.ToString, Convert.ToInt32 (int) and Convert.ToInt64 (long)
int myInt = 10;
double myDouble = 5.25;
bool myBool = true;
Console.WriteLine(Convert.ToString(myInt));
Console.WriteLine(Convert.ToDouble(myInt));
Console.WriteLine(Convert.ToInt32(myDouble));
Console.WriteLine(Convert.ToString(myBool));
What method can find the highest value of x and y?
Math.Max();
What method can find the minimum value of x and y?
Math.Min();
What method can find the square root of a value?
Math.Sqrt();
What method can find the absolute value of number?
Math.Abs();
What method will round a number to the nearest whole number?
Math.Round();
How can you find the length of a string?
The Length property.
.Length
How do you convert a string to upper or lower case?
.ToUpper()
.ToLower()
What is the method to concatenate two strings?
string.Concat()
How do you reference a certain character in a string?
With the index number.
string[0]
What method can find the index value of a certain character?
string.IndexOf(“x”);