C# Flashcards

1
Q

class labeled ‘abstract’ (3 things)

A

class is intended only to be base class of other classes; can’t be instantiated; a class dervied from abstract class must implement all abstract members

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

method or property labeled ‘abstract’ (3 things)

A

method does not have implementation; only allowed in abstract class; no {}, goes right to ;

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

Cast that returns null instead of raising an exception

A

EXPRESSION as TYPE

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

How to call method on base class that has been overridden?

A

Use base.method();

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

How to call the base class’s constructor from the derived class constructor?

A

public class DerivedClass(int i) : base(int i) {…}

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

Data type for unsigned 8 bit integer

A

byte

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

Data type for unicode 2 byte character

A

char

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

How to raise an exception on code that could overflow?

A

checked { block; } or checked(expression)

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

Data type for numeric 16 byte

A

decimal

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

Suffix for literal of type decimal

A

m

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

For a generic (template), how to get an initialization value for the type?

A

= default(T);

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

How to create a function pointer?

A

delegate returntype name();

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

Suffix for literal of type double

A

d

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

How to declare a variable of nullable bool type?

A

bool? x;

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

How to declare an enum with a non-int underlying type?

A

enum EnumName : newtype {value, value};

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

How to declare an explicit cast conversion operator?

A

public static explicit operator NewTypeName(OldTypeName x) { return new NewTypeName(…) };

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

How to declare an implicit cast conversion operator?

A

public static implicit operator NewTypeName(OldTypeName x) { return new NewTypeName(…) };

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

What does extern method marking do?

A

specifies the implementation of the method is external

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

Why use finally in try catch?

A

Clean up in case the catch returns or throws a new exception

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

How to pin the location of a variable in unsafe code?

A

fixed (int* x = pinnedvar)

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

Suffix for literal of type float

A

f

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

How to redirect to a different switch case?

A

goto case 5;

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

How to declare an interface?

A

interface Iname { void func(); }

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

How to declare something as only accessible in this assembly?

A

internal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How to check if object has a type or has a derivation of a type
if (obj is myObj) { }
26
How to block a critical section that can only be run by one thread at a time?
Object thisLock = new Object(); lock(thisLock) { statements; }
27
Suffix for literal of type long
L
28
singed integer types (1 byte, 2 byte, 4 byte, 8 byte)
sbyte, short, int, long
29
In derived class, new vs override method?
If reference to base class is used, with NEW the base class is called, with OVERRIDE the derived class is called
30
Generic class constraint requiring a constructor with no parameters
class ClassName where T : new() {}
31
Overload the addition operator
public static ReturnType operator +(Type a, Type b) { }
32
Method parameter out vs ref
ref requires initialization of the variable first
33
How to expect multiple parameters of any type?
void foo(params object[] list) { }
34
What does readonly modifier do?
Member variable can only be set in declaration or in a constructor of that class
35
unsigned integer types (1 byte, 2 byte, 4 byte, 8 byte)
byte, ushort, uint ulong
36
What does sealed modifier on a class do?
Stops inheritence from the class
37
What does sealed modifier on a method do?
Stops overriding of that method
38
fractional data types (4 byte, 8 byte, 16 byte)
float, double, decimal
39
How to allocate a block of memory on the stack (in unsafe code)?
int* block = stackalloc int[100];
40
What does static modifier mean on a class? (2 things)
Only one instance exists; all members must be static
41
What does static modifier mean on a method?
Method must be called from class name, not instance name
42
Three uses of keyword this?
Differentiate between params and members, pass instance to another func, indexer
43
How to suppress overflow checking for a block of code?
unchecked { block; } or unchecked(expression);
44
How to designate a block of code to allow pointers?
unsafe { block; } or unsafe void foo() { };
45
How to create an alias for a class?
using X as namespace.ClassName;
46
How to temporarily use a variable in a block of code?
using (variable = new constructor()) { }
47
What does modifier volatile do?
indicates a member variable could be modified by multiple threads
48
What are add and remove keywords used for?
when client code subscribes or unsubscribes from an event (structured like property)
49
typeof vs GetType vs is
typeof takes a type name specified at compile time, GetType returns runtime type of instance, is returns true if instance in inheritence tree
50
How to declare variable that could have any type?
dynamic
51
How to split a class across multiple files?
use the modifier partial
52
What does partial modifier mean for a method?
separates signature from implementation, like .cpp and .h files. If no implementation, signature is removed
53
How to declare function-scope variable with implicit type?
var x = 10;
54
How to specify generic, where the type supports a specific interface?
public class MyClass where T:IComparable {}
55
Event sequence when a button on a winform is clicked?
Enter GotFocus MouseDown MouseUp Click
56
Show() vs ShowDialog()
ShowDialog() is modal
57
Anchoring vs docking
Anchoring size is constant, docking location is constant
58
What is an asynchronous callback delegate?
Function gets passed in, but may not be called before the function exits, could be called after
59
What is covariance in delegates?
Permits a method to have a more derived return type than what is defined in the delegate
60
Dispose vs Finalize vs Destructor
Finalize = Destructor, Dispose should be called by your code