C# Flashcards Preview

Interview - C# > C# > Flashcards

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

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?



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.


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.


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.


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.


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.)


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.


What is Managed code?

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


What is a Sealed class?

Sealed classes cannot be inherited.


What is a Partial class?

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


What is an Abstract class?

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


What is a Static class?

Static classes are not instantiated but called and used directly.


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.


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.


What are namespaces in .Net?

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