H1-3 Flashcards

1
Q

Convert to other type

A

System.Convert.To…(value)

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

[struct] do you always get default values?

A

No, only when using new, calls the constructor

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

[struct] how many parameters go in the constructor?

A

All fields otherwise compile exception.

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

[Optional] what is a restriction with optional parameters?

A

(Par1 = 1, Par2 = 2), can’t do (Par2 only) because then you need to do Par1 also.

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

How can you call parameters by name

A

(parameter1 : value, parameter2 : value)

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

give an example of a for loop with empty definitions

A

for(;;)
{
if(xxxx) break;
}

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

what is an indexed property?

A
public class IPAddress
{
private int[] ip;
public int this[int index]
{
get
{
return ip[index];
}
set
{
if (value == 0 || value == 1)
ip[index] = value;
else
throw new Exception("Invalid value");
}
}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you use an indexed property

A
IPAddress myIP = new IPAddress();
// initialize the IP address to all zeros
for (int i = 0; i < 32; i++)
{
myIP[i] = 0;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

give an example of a generic queue class

A
// example of a generic style Queue
public class GenericQueue{T}
{
public void Enqueue(T obj);
public T DeQueue();
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Give an example of a generic methode.

A
// example of generic method with type parameters
public void Swap{T}(T valueOne, T valueTwo)
{
T temp = valueOne;
valueOne = valueTwo;
valueTwo = temp;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

give an example of an enumeration in code

A

enum Months {Jan, Feb, March, …}

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

give an example of an enumuration that is not an int

A

enum Months : byte {Jan, Feb, …}

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

give an example of an enumeration that starts with 4 and not the default 0.

A

enum Months {Jan = 1, Feb, … }

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

Give an example of an extention methode

A
public static class MyExtendedMethods
{
public static int square(this int num)
{
int result = 0;
result = num * num;
return result;
}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How many indexed properties can a class have?

A

One.

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

Can you swap named arguments around?

public static double rectArea(double length, double width) -> double area = rectArea(length: 35.0, width: 25.5);

A

Yes

17
Q

How do you implement an abstract method in a inherited class?

A

public override method signature

18
Q

what is a abstract class?

A

A call that you can’t create an instance from. Used to inherit from.