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
Q

How to check if object has a type or has a derivation of a type

A

if (obj is myObj) { }

26
Q

How to block a critical section that can only be run by one thread at a time?

A

Object thisLock = new Object(); lock(thisLock) { statements; }

27
Q

Suffix for literal of type long

A

L

28
Q

singed integer types (1 byte, 2 byte, 4 byte, 8 byte)

A

sbyte, short, int, long

29
Q

In derived class, new vs override method?

A

If reference to base class is used, with NEW the base class is called, with OVERRIDE the derived class is called

30
Q

Generic class constraint requiring a constructor with no parameters

A

class ClassName where T : new() {}

31
Q

Overload the addition operator

A

public static ReturnType operator +(Type a, Type b) { }

32
Q

Method parameter out vs ref

A

ref requires initialization of the variable first

33
Q

How to expect multiple parameters of any type?

A

void foo(params object[] list) { }

34
Q

What does readonly modifier do?

A

Member variable can only be set in declaration or in a constructor of that class

35
Q

unsigned integer types (1 byte, 2 byte, 4 byte, 8 byte)

A

byte, ushort, uint ulong

36
Q

What does sealed modifier on a class do?

A

Stops inheritence from the class

37
Q

What does sealed modifier on a method do?

A

Stops overriding of that method

38
Q

fractional data types (4 byte, 8 byte, 16 byte)

A

float, double, decimal

39
Q

How to allocate a block of memory on the stack (in unsafe code)?

A

int* block = stackalloc int[100];

40
Q

What does static modifier mean on a class? (2 things)

A

Only one instance exists; all members must be static

41
Q

What does static modifier mean on a method?

A

Method must be called from class name, not instance name

42
Q

Three uses of keyword this?

A

Differentiate between params and members, pass instance to another func, indexer

43
Q

How to suppress overflow checking for a block of code?

A

unchecked { block; } or unchecked(expression);

44
Q

How to designate a block of code to allow pointers?

A

unsafe { block; } or unsafe void foo() { };

45
Q

How to create an alias for a class?

A

using X as namespace.ClassName;

46
Q

How to temporarily use a variable in a block of code?

A

using (variable = new constructor()) { }

47
Q

What does modifier volatile do?

A

indicates a member variable could be modified by multiple threads

48
Q

What are add and remove keywords used for?

A

when client code subscribes or unsubscribes from an event (structured like property)

49
Q

typeof vs GetType vs is

A

typeof takes a type name specified at compile time, GetType returns runtime type of instance, is returns true if instance in inheritence tree

50
Q

How to declare variable that could have any type?

A

dynamic

51
Q

How to split a class across multiple files?

A

use the modifier partial

52
Q

What does partial modifier mean for a method?

A

separates signature from implementation, like .cpp and .h files. If no implementation, signature is removed

53
Q

How to declare function-scope variable with implicit type?

A

var x = 10;

54
Q

How to specify generic, where the type supports a specific interface?

A

public class MyClass where T:IComparable {}

55
Q

Event sequence when a button on a winform is clicked?

A

Enter GotFocus MouseDown MouseUp Click

56
Q

Show() vs ShowDialog()

A

ShowDialog() is modal

57
Q

Anchoring vs docking

A

Anchoring size is constant, docking location is constant

58
Q

What is an asynchronous callback delegate?

A

Function gets passed in, but may not be called before the function exits, could be called after

59
Q

What is covariance in delegates?

A

Permits a method to have a more derived return type than what is defined in the delegate

60
Q

Dispose vs Finalize vs Destructor

A

Finalize = Destructor, Dispose should be called by your code