C# Flashcards

1
Q

What framework does C# run on?

A

The .NET Framework.

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

What method is used to print to console?

A

Console.WriteLine(“message”);

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

How do you use writeline placeholders?

A

Console.WriteLine(“My name is {0} and I am {1} years old”, x, y);

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

What method is used to get user input?

A

Console.ReadLine();

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

How do you convert value types?

A

Convert.ToXXX

int32, bool, int64

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

How do you implicitely type a variable?

A

var (instead of int or bool or whatever)

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

What is the difference between ++i and i++?

A

++i increments then proceeds with the expression, i++ does the opposite.

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

How do you use switch cases?

A
switch (num){
case 1:
//code
break;
case 2:
//code
break;
default:
//code
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the continue keyword do?

A

Breaks the current iteration only

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

How do you use conditional operator?

A

msg = Exp1 ? Exp2 : Exp 3;

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

How do you set a default value for a method parameter?

A

void method(int x, int y=2);

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

How can you place your arguments in any order when calling a method?

A

By calling the parameter variables in the arguments

Ex: method(x: 5, y: 8);

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

How can you use references in methods and change variable values from a method?

A

with the ref keyword
void method(ref int y);
method(ref x)

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

What is similar to a ref, but does not require you to initialize a variable?

A

out

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

What is overloading?

A

Defining methods with the same names but with different parameters.

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

What is the protected access modifier limited to?

A

Classes and descendants

17
Q

How do you use properties?

A

public string Name {get;set;} //default
public int Age {get{return age;}set{if(value­ == 0
age = 0}}

18
Q

How do you use arrays?

A

int[] myArray = new int[5];

string[] names = new string[3] {“john”, “bob”, “chloe”};

19
Q

What is a static member?

A

A member that only belongs to a class, not an object.

20
Q

What does “this” refer to?

A

The current instance of the class

21
Q

What does the readonly keyword do?

A

Makes it so a member can only be modified through a constructor.

22
Q

What is operator overloading?

A

A way of redefining operators

b + b2 (the + now works with objects)

23
Q

How do you use inheritance?

A

class Dog : Animal {}

24
Q

What is polymorphism?

A

A way to re-implement the same method name through a derived class

25
Q

How do you use polymorphism?

A
base class must have "virtual" keyword
derived class must have "override" keyword
26
Q

What are abstract classes?

A

A class that can’t be instantiated.

27
Q

What is the advantage of using an interface?

A

A class can implement multiple interfaces

28
Q

How do you use exceptions?

A
try{
//code
}
catch(Exception e){
//code
}
finally{}
29
Q

How do you use generics?

A
void method­(T a, T b){
//code
}
method(a, b); //could have been , , etc.