C# Flashcards

1
Q

✅Differences Array vs ArrayList (4)

A

Array - fixed size - strong typed - force to iterate by index - faster ArrayList - re-sizable - generic typed - linq - slower

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

✅ Array.Clone VS Array.CopyTo

A

Clone: returns a new array CopyTo: Copies the elements into another existing array

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

✅ Abstract class vs Interface (6)

A

Abstract Class - Interface 1 - Method Signature 2 - Constructor 3 - Multiple Inheritance 4- static members 5 - access modifiers 6 - only contains methods.

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

✅ Dispose vs Finalize

A

You call dispose to release a db connection, etc.

Finalize is called by the GC.
A destructor is an override version of the Finalize method, that executes the destructor’s code and then calls the base class’ Finalize method.

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

✅ Struct vs Class

A

1 - Structs are value types / stored on the stack. 2- Structs don’t support inheritance 3- Structs are sealed type 4- Structs cannot have explicit parameterless constructors 5- Structs cannot have destructors

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

✅ “is” vs “as” (2)

A

“is “ 1 - to check runtime type of an object. 2 - returns a boolean “as” 1 - to cast objects 2- returns an object

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

✅ throw vs throw ex (1)

A

throw ex resets the stack trace, so your errors would appear to originate from HandleException throw the original offender would be preserved

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

✅reflection

A

1 - dynamically create an instance of a type, 2 - bind the type to an existing object, 3- or get the type from an existing object and invoke its methods or access its fields and properties.

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

✅ Unmanaged Code

A

N/A

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

✅ boxing vs unboxing

A

N/A

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

✅const vs readonly (1)

A

const is a compile-time constant readonly is assigned only once at run-time

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

✅ ref (1) vs (2) out

A

ref 1- should be initialized before being used. out 1- isn’t required to be initialized before. 2- it is used when returning multiple parameters

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

✅ string vs stringbuilder

A

N/A

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

✅ SortedList (2) vs (2) SortedDictionary

A

SortedList 1 - Less memory 2- faster: if the list is populated all at once from sorted data, SortedDictionary 1- more memory 2 - faster insertion and removal operations for unsorted data, O(log n) as opposed to O(n) for SortedList

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

✅ Hashtable (3) vs (2) Dictionary

A

Hashtable 1 - Non-generic 2 - not type-safe 3- Uses a hash function to choose an index to store the value Dictionary 1 - Generic 2 - Type-safe

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

✅ Stack (2) vs (2) Queue

A

Stack 1- LIFO 2- Push / pop Queue 1- FIFO 2- Enqueue / Dequeue

17
Q

✅ Method overriding (2) vs (2) Method hiding

A

hiding 1 - uses the new keyword 2 - when a base class points to its child class,the base class will call the base class method override 1- uses the virtual keyword and @override over the method. 2- when a base class points to its child class the base class will call the overridden method

18
Q

✅ Int64 vs UInt64

A

U stands for unsigned integer, it stores only positive values

19
Q

✅ byte vs sbyte

A

s stands for signed integer, it stores positive and negative values

20
Q

✅ What is Lazy?

A

Lazy initialization of an object means that its creation is deferred until it is first used

21
Q

✅ Singleton VS Static Class

A

Singleton
Can implement interfaces
Can be passed as arguments
Can be assigned to variables
Can have state
Can be serialized

Static Class
No interfaces
Cannot be passed as arguments
Cannot be assigned
Can only access global state
No support for serialization