C# Flashcards

1
Q

How is C# different from C?

A

C being the procedural language while C# is a more object-oriented language.
C# supports automatic garbage collection by Common Language Runtime (CLR)
C# primarily needs a .NET framework to execute while C is a platform-agnostic language.

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

What type of language is C#

A

Object-oriented programming language

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

What is Common Language Runtime (CLR)?

A

CLR handles memory management, garbage collection, security handling

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

What is garbage collection in C#?

A

Process of freeing up memory that is captured by unwanted objects
Garbage collection happens in three cases:
If the occupied memory by the objects exceeds the pre-set threshold value.
If the garbage collection method is called
If your system has low physical memory

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

What are the types of classes in C#?

A

Static class: Static class, defined by the keyword ‘static’ does not allow inheritance.
Partial class: Partial class, defined by the keyword ‘partial’ allows its members to partially divide or share source (.cs) files.
Abstract class: Abstract classes are classes that cannot be instantiated where you cannot create objects. Abstract classes work on the OOPS concept of abstraction. Abstraction helps to extract essential details and hide the unessential ones.
Sealed class: Sealed classes are classes that cannot be inherited. Use the keyword sealed to restrict access to users to inherit that class.

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

What is a managed and unmanaged code?

A

Managed code lets you run the code on a managed CLR runtime environment in the .NET framework.
Unmanaged code is when the code doesn’t run on CLR, it is an unmanaged code that works outside the .NET framework.

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

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

A

Abstract classes are classes that cannot be instantiated ie. that cannot create an object.
The interface is like an abstract class because all the methods inside the interface are abstract methods.

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

What are the differences between ref and out keywords?

A

C# ref keywords pass arguments by reference and not value.
C# out keywords pass arguments within methods and functions.

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

What are extension methods in C#?

A

Extension methods help to add new methods to the existing ones.

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

What are Generics in C#?

A

Generics in C# mean not linked to any specific data type. Good for code reusability

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

What is the difference between an Array and ArrayList in C#?

A

An array is a collection of similar variables clubbed together under one common name. While ArrayList is a collection of objects that can be indexed individually. With ArrayList you can access a number of features like dynamic memory allocation, adding, searching, and sorting items in the ArrayList.

When declaring an array the size of the items is fixed therefore, the memory allocation is fixed. But with ArrayList, it can be increased or decreased dynamically.
Array belongs to system.array namespace while ArrayList belongs to the system.collection namespace.
All items in an array are of the same datatype while all the items in an ArrayList can be of the same or different data types.
While arrays cannot accept null, ArrayList can accept null values.

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

What is inheritance? Does C# support multiple inheritance?

A

Inheritance means acquiring some of the properties from a master class.
C# doesn’t support multiple inheritances.

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

What are Properties in C#?

A

Properties in C# are public members of a class where they provide the ability to access private members of a class.

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