General Flashcards

1
Q

What are the data types in C#?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is type casting?

A

Type casting is when you assign a value of one data type to another type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is implicit casting?

A

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;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is explicit casting?

A

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;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the methods to explicitly convert a data type?

A

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));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What method can find the highest value of x and y?

A

Math.Max();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What method can find the minimum value of x and y?

A

Math.Min();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What method can find the square root of a value?

A

Math.Sqrt();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What method can find the absolute value of number?

A

Math.Abs();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What method will round a number to the nearest whole number?

A

Math.Round();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can you find the length of a string?

A

The Length property.

.Length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you convert a string to upper or lower case?

A

.ToUpper()

.ToLower()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the method to concatenate two strings?

A

string.Concat()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you reference a certain character in a string?

A

With the index number.

string[0]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What method can find the index value of a certain character?

A

string.IndexOf(“x”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How does the Substring method work?

A

Input the starting position in the arguments and the method will return a string starting at that character.

// Full name
string name = "John Doe";
// Location of the letter D
int charPos = name.IndexOf("D");
// Get last name
string lastName = name.Substring(charPos);
17
Q

What is the escape character in C#

A

\

18
Q

How do you create a new line, tab, and backspace in text in C#?

A

\n
\t
\b

19
Q

What is the syntax for a ternary operator?

A

(condition) ? “True” : “False”;

(time < 18) ? “Good day.” : “Good evening.”;

20
Q

What is the foreach loop syntax?

A
for(type variableName in arrayName){
//code block
}
21
Q

Which character do you use to make a variable nullable?

A

’?’

Examples:
int? num1 = null;
double? num2 = new double?();
bool? boolval = new bool?();