C# Flashcards
✅Differences Array vs ArrayList (4)
Array - fixed size - strong typed - force to iterate by index - faster ArrayList - re-sizable - generic typed - linq - slower
✅ Array.Clone VS Array.CopyTo
Clone: returns a new array CopyTo: Copies the elements into another existing array
✅ Abstract class vs Interface (6)
Abstract Class - Interface 1 - Method Signature 2 - Constructor 3 - Multiple Inheritance 4- static members 5 - access modifiers 6 - only contains methods.
✅ Dispose vs Finalize
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.
✅ Struct vs Class
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
✅ “is” vs “as” (2)
“is “ 1 - to check runtime type of an object. 2 - returns a boolean “as” 1 - to cast objects 2- returns an object
✅ throw vs throw ex (1)
throw ex resets the stack trace, so your errors would appear to originate from HandleException throw the original offender would be preserved
✅reflection
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.
✅ Unmanaged Code
N/A
✅ boxing vs unboxing
N/A
✅const vs readonly (1)
const is a compile-time constant readonly is assigned only once at run-time
✅ ref (1) vs (2) out
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
✅ string vs stringbuilder
N/A
✅ SortedList (2) vs (2) SortedDictionary
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
✅ Hashtable (3) vs (2) Dictionary
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
✅ Stack (2) vs (2) Queue
Stack 1- LIFO 2- Push / pop Queue 1- FIFO 2- Enqueue / Dequeue
✅ Method overriding (2) vs (2) Method hiding
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
✅ Int64 vs UInt64
U stands for unsigned integer, it stores only positive values
✅ byte vs sbyte
s stands for signed integer, it stores positive and negative values
✅ What is Lazy?
Lazy initialization of an object means that its creation is deferred until it is first used
✅ Singleton VS Static Class
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