C# Flashcards Preview

Interview - C# > C# > Flashcards

Flashcards in C# Deck (43)
Loading flashcards...
1

What is Jagged Array in C#?

A Jagged array is an array of arrays.

2

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

System.Object

3

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.

4

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.

5

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.

6

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;

7

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.

8

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.

9

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.

10

Can multiple catch blocks be executed?

No, the first matching catch block will be executed.

11

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.

12

What is serialization?

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

13

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.

14

What are indexers in C# .NET?

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

15

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.

16

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.

17

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.

18

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.

19

What is an interface?

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

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

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

What are the SOLID principles?

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

What are the fundamental concepts of Object Oriented Programming?

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

What is Managed code?

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

24

What is a Sealed class?

Sealed classes cannot be inherited.

25

What is a Partial class?

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

26

What is an Abstract class?

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

27

What is a Static class?

Static classes are not instantiated but called and used directly.

28

What are the differences between a Class and a Struct?

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

29

What is the difference between Virtual methods and Abstract methods?

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

What are namespaces in .Net?

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