C# Flashcards
class labeled ‘abstract’ (3 things)
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
method or property labeled ‘abstract’ (3 things)
method does not have implementation; only allowed in abstract class; no {}, goes right to ;
Cast that returns null instead of raising an exception
EXPRESSION as TYPE
How to call method on base class that has been overridden?
Use base.method();
How to call the base class’s constructor from the derived class constructor?
public class DerivedClass(int i) : base(int i) {…}
Data type for unsigned 8 bit integer
byte
Data type for unicode 2 byte character
char
How to raise an exception on code that could overflow?
checked { block; } or checked(expression)
Data type for numeric 16 byte
decimal
Suffix for literal of type decimal
m
For a generic (template), how to get an initialization value for the type?
= default(T);
How to create a function pointer?
delegate returntype name();
Suffix for literal of type double
d
How to declare a variable of nullable bool type?
bool? x;
How to declare an enum with a non-int underlying type?
enum EnumName : newtype {value, value};
How to declare an explicit cast conversion operator?
public static explicit operator NewTypeName(OldTypeName x) { return new NewTypeName(…) };
How to declare an implicit cast conversion operator?
public static implicit operator NewTypeName(OldTypeName x) { return new NewTypeName(…) };
What does extern method marking do?
specifies the implementation of the method is external
Why use finally in try catch?
Clean up in case the catch returns or throws a new exception
How to pin the location of a variable in unsafe code?
fixed (int* x = pinnedvar)
Suffix for literal of type float
f
How to redirect to a different switch case?
goto case 5;
How to declare an interface?
interface Iname { void func(); }
How to declare something as only accessible in this assembly?
internal