C# Flashcards
C# interview prep
What is Jagged Array in C#?
A Jagged array is an array of arrays.
Which class acts as a base class for all the data types in .Net?
System.Object
What is boxing/unboxing in C#?
When a value type is converted to object type and when an object type is converted back to a value type.
What are the ways that parameters can be passed to a method?
Value, Reference (and Output).
Value parameters hold a copy of the passed value.
Reference parameters holds a reference to the memory location of an argument.
Output parameters are uninitialized reference variables. They allow the method to return more than one value.
Can multiple values be returned from a function in C#?
Normally a function can only return a single value but by using output parameters, you can return more than one value from a function.
What are dynamic type variables in C#?
Dynamic data type can store any type of value. Type checking for these takes place at run-time.
Example:
dynamic d = 20;
What are Value and Reference types and whats the difference between them?
A Value type holds the data within its own memory allocation and a Reference type contains an address to another memory location that holds the real data.
Reference Type variables are stored in the heap while Value Type variables are stored in the stack.
What is the difference between the dynamic type and the object type variables?
Dynamic types are similar to Object types except that type checking for Object types takes place at compile time, whereas the Dynamic type is type checked at run time.
Whats the difference between String and StringBuilder?
Strings are immutable (their values cannot be changed once they have been created) so any modification to a string value results in a completely new string instance. The mutable System.Text.StringBuilder class should be used when string values will change.
Can multiple catch blocks be executed?
No, the first matching catch block will be executed.
What is the using statement for?
The using block is used to obtain a resource and then automatically dispose of that resource when the execution of block is completed.
What is serialization?
Serialization is the process of converting an object into its binary format.
Can “this” be used within a static method?
No because “this” refers to the current instance and static methods are just call and used, there are no instances created.
What are indexers in C# .NET?
Indexers allows the instances of a class to be indexed in the same way as array.
What is difference between the “throw” and “throw ex” in .NET?
The “throw” statement will show the entire error stack whereas “throw ex” will only show the stack trace from the point where the exception is thrown.
What are C# attributes?
An attribute is a declarative tag placed above classes, methods, etc. that is used to convey behavioral
information to the runtime.
What is difference between the “is” and “as” operators in C#?
The “is” operator is used to check the compatibility of an object with a given type and it returns the result as Boolean. The “as” operator is used for casting an object to a different type.
What are extension methods?
Extension methods allow you to add methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.