C# Flashcards

C# interview prep

1
Q

What is Jagged Array in C#?

A

A Jagged array is an array of arrays.

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

Which class acts as a base class for all the data types in .Net?

A

System.Object

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

What is boxing/unboxing in C#?

A

When a value type is converted to object type and when an object type is converted back to a value type.

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

What are the ways that parameters can be passed to a method?

A

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.

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

Can multiple values be returned from a function in C#?

A

Normally a function can only return a single value but by using output parameters, you can return more than one value from a function.

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

What are dynamic type variables in C#?

A

Dynamic data type can store any type of value. Type checking for these takes place at run-time.

Example:

dynamic d = 20;

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

What are Value and Reference types and whats the difference between them?

A

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.

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

What is the difference between the dynamic type and the object type variables?

A

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.

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

Whats the difference between String and StringBuilder?

A

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.

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

Can multiple catch blocks be executed?

A

No, the first matching catch block will be executed.

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

What is the using statement for?

A

The using block is used to obtain a resource and then automatically dispose of that resource when the execution of block is completed.

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

What is serialization?

A

Serialization is the process of converting an object into its binary format.

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

Can “this” be used within a static method?

A

No because “this” refers to the current instance and static methods are just call and used, there are no instances created.

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

What are indexers in C# .NET?

A

Indexers allows the instances of a class to be indexed in the same way as array.

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

What is difference between the “throw” and “throw ex” in .NET?

A

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.

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

What are C# attributes?

A

An attribute is a declarative tag placed above classes, methods, etc. that is used to convey behavioral
information to the runtime.

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

What is difference between the “is” and “as” operators in C#?

A

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.

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

What are extension methods?

A

Extension methods allow you to add methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.

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

What is an interface?

A

An Interface is a class with no implementation. The only thing that it contains is the declaration of methods, properties, and events.

An interface only has public methods declarations without definitions. These abstract methods must be implemented in the inherited classes.

20
Q

What’s the difference between an interface and abstract class?

A

Interfaces have all the methods having only declaration but no definition.
In an abstract class, we can have some concrete methods.

In an interface class, all the methods are public. 
An abstract class may have private methods.
21
Q

What are the SOLID principles?

A

SOLID is a mnemonic acronym for five design principles intended to make software designs more understandable, flexible and maintainable.

  1. Single responsibility principle
    (All classes and methods should have only a single responsibility.)
  2. Open Closed principle
    (Software entities should be open for extension, but closed for modification.)
  3. Liskov Substitution principle
    (Objects in a program should be replaceable with instances of their subtypes.)
  4. Interface Segregation principle
    (Many specific interfaces are better than one general-purpose interface.)
  5. Dependency Inversion principle
    (Depend upon abstractions, not concretions and create loosely coupled code.)
22
Q

What are the fundamental concepts of Object Oriented Programming?

A

Abstraction – It is a process of identifying the critical behavior and data of an object and eliminating the irrelevant details.

Encapsulation – The Internal representation of an object is hidden from the view outside object’s definition.

Inheritance – It is the ability to create new classes from another class.

Polymorphism – The name means, one name, many forms. It is achieved by having multiple methods with the same name but different implementations.

23
Q

What is Managed code?

A

This refers to any code that runs on the .Net framework Common Language Runtime.

24
Q

What is a Sealed class?

A

Sealed classes cannot be inherited.

25
Q

What is a Partial class?

A

Partial classes are classes that are divided up between multiple .cs files.

26
Q

What is an Abstract class?

A

Abstract classes cannot be instantiated, only inherited. They should contain at least one method.

27
Q

What is a Static class?

A

Static classes are not instantiated but called and used directly.

28
Q

What are the differences between a Class and a Struct?

A

Classes supports inheritance but Structs do not. Classes are passed by reference whereas Structs are passed by value.

29
Q

What is the difference between Virtual methods and Abstract methods?

A

Virtual methods have a default implementation that can optionally be overridden (using the Override keyword) in the derived class.
Abstract methods however do not have any implementation and the derived classes are required to implement the abstract methods.

30
Q

What are namespaces in .Net?

A

Namespaces refers to the organize of .Net class and other items into logically groups.

31
Q

What is Abstraction?

A

Abstraction refers to displaying only the essential features of the class and hiding the unnecessary information.

32
Q

What is the difference between the Continue and Break Statement?

A

The Break statement completely exits out of the loop. The Continue statement however only exits out of the current iteration of the loop.

33
Q

What are Regular expressions?

A

Regular expression is a template to match a set of input.

34
Q

What is Parsing?

A

Parsing is converting a string into another data type.

35
Q

What is a Delegate?

A

A Delegate is a variable that holds the reference to a method. Hence it is a function pointer of reference type. The delegate and the method that it refers to can have the same signature.

36
Q

What are the different types of Delegates?

A

Single, multicast and generic.

A single delegate can call a single method.

A multicast delegate can call multiple methods.

Generic Delegate – It does not require an instance of delegate to be defined. It is of three types, Action, Funcs and Predicate.

37
Q

What is Reflection in C#?

A

Reflection is the ability to access the metadata of the assembly during runtime.

38
Q

What are Generics?

A

Generics allows you to create classes and methods that do not have any specific data type. The data type is assigned during run-time.

39
Q

What is a process?

A

A “process” is a program that has been loaded into memory along with all the resources it needs to operate.

40
Q

What are deadlocks?

A

A Deadlock is where two or more processes are waiting for each other to finish so neither can complete. This usually occurs in multi-threading.

41
Q

What is a Thread pool?

A

A Thread pool is a collection of threads. These threads can be used to perform tasks without disturbing the primary thread. Once the thread completes the task, the thread returns to the pool.

42
Q

What are pointer types in C#?

A

Pointer type variables store the memory address of another type.
Example:
char* cptr;
int* iptr;

43
Q

What’s the difference between Polymorphism vs Inheritance?

A

Inheritance refers to using the structure and behavior of a parent class in a derived class.

Polymorphism refers to changing the behavior of a parent class in the derived class.

Examples of Polymorphism would be:
At run-time
When virtual methods of a parent class are overridden in derived class.
Or
When instances of a derived class are used in place of a their parent class.

44
Q

What are the types of classes in C#?

A

Static class - These cannot be inherited from or instantiated.

Partial class - These allow its members to partially divide or share source (.cs) files.

Abstract class - These are used as base classes to inherit from and cannot be instantiated.

Sealed class - These cannot be inherited but can be instantiated.

45
Q

What is an abstract class?

A

An abstract class serves only as a base class for other classes to inherit from, it cannot be instantiated. It’s used to define base types with a common set of behaviors or properties that derived classes should have.

46
Q

What is the difference between an abstract class and an interface?

A

An abstract class allows you to create functionality that subclasses can implement or override. An interface only allows you to define functionality, not implement it.