General Flashcards

1
Q

What is C#

A

C# is an object-oriented programming language that was created by Microsoft.
It runs on the .NET framework.
Similar to C++ and Java.

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

How is C# different from C

A

C supports procedural programming; C# is object-oriented.
C supports pointers; C# pointers are used only in unsafe mode.
No garbage collection in C; in C# garbage collection is managed by the Common Language Runtime (CLR).
C can be executed cross-platform; C# requires the .NET framework.
C achieves low level abstraction; C# offers a high degree of abstraction.

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 is the basic and Virtual Machine component of the .NET framework. It is the runtime environment in the .NET Framework.
It is responsible for managing execution of .NET programs regardless of the language.

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

What are Indexers in C# .NET

A

Indexers are known as smart arrays in C#. They allow instances of a class to be indexed in the same way as an array.

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

What is the JIT compiler process

A

Just-in-Time compiler is a part of the Common Language Runtime in .NET. It is responsible for managing the execution of .NET programs.
A language specific compiler converts the source code to the intermediate language.
This intermediate language is then converted into the machine code by the Just-In-Time (JIT) compiler.
This machine code is specific to the computer environment that the JIT compiler runs on.

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

What is garbage collection in C#

A

When a class object is created at runtime, certain memory space is allocated to it in the heap memory. However, after all the actions related to the object are completed in the program, the memory space allocated to it is a waste as it cannot be used. In this case, garbage collection is very useful as it automatically releases the memory space after it is no longer required.

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

What are the conditions under which Garbage Collection runs

A

If the system has low physical memory, then garbage collection is necessary.

If the memory allocated to various objects in the heap memory exceeds a pre-set threshold, then garbage collection occurs.

If the GC.Collect method is called, then garbage collection occurs. However, this method is only called under unusual situations as normally garbage collector runs automatically.

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

What are the types of classes in C#

A
Abstract class
Partial class
Sealed class
Static class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the difference between an abstract class and an interface

A

AC contains both declaration and definition parts; Int contains only a declaration part.
Cannot achieve multiple inheritance with AC; May achieve multiple inheritance with Int.
AC contains a constructor; Int does not.
AC can contain static members; Int cannot.
AC can contain different modifiers such as public, private, etc; Int must have all members as public.
AC performance is faster than Int.
AC is used to implement core identity of class; Int used to implement peripheral abilities of a class.

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

What are extension methods in C#

A

They allow you to add new methods in the existing class or in the structure without modifying the source code of the original type, and you do not require any kind of special permission from the original type and there is no need to re-compile the original type.

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

Does C# allow for multiple inheritance?

A

No, C# does not support multiple class inheritance

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

What is Managed Code?

A

Managed Code is aimed to get the services of the managed runtime environment like CLR.

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

What is Unmanaged Code

A

Code that is directly executed by the operating system. It is always aimed at the processor architecture and depends on the computer architecture.

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

What is the difference between a struct and a class in C#

A

A class is a user-defined blueprint or prototype from which objects are created. Basically, a class combines the fields and methods(member function which defines actions) into a single unit.

A structure is a collection of variables of different data types under a single unit. It is almost similar to a class because both are user-defined data types and both hold a bunch of different data types.

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

What is an enum in C#

A

Enumeration (or enum) is a value data type in C#. It is mainly used to assign the names or string values to integral constants, which make a program easy to read and maintain.

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

What is the ref keyword

A

The ref keyword indicates that a value is passed by reference. It is used in four different contexts:

In a method signature and in a method call, to pass an argument to a method by reference.

In a method signature, to return a value to the caller by reference.

In a member body, to indicate that a reference return value is stored locally as a reference that the caller intends to modify. Or to indicate that a local variable accesses another value by reference.

In a struct declaration, to declare a ref struct or a readonly ref struct.

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

What is the out keyword

A

The out is a keyword in C# which is used for passing the arguments to methods as a reference type. It is generally used when a method returns multiple values. The out parameter does not pass the property.

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

What are properties

A

Properties are the special type of class members that provides a flexible mechanism to read, write, or compute the value of a private field. Properties can be used as if they are public data members, but they are actually special methods called accessors. This enables data to be accessed easily and helps to promote the flexibility and safety of methods. Encapsulation and hiding of information can also be achieved using properties. It uses pre-defined methods which are “get” and “set” methods which help to access and modify the properties.

19
Q

Types of Accessors

A

Read and Write Properties: When property contains both get and set methods.
Read-Only Properties: When property contains only the get method.
Write Only Properties: When property contains only set method.
Auto Implemented Properties: When there is no additional logic in the property accessors, and it introduces in C# 3.0

20
Q

What are partial classes

A

It provides a special ability to implement the functionality of a single class into multiple files and all these files are combined into a single class file when the application is compiled. A partial class is created by using a partial keyword. This keyword is also useful to split the functionality of methods, interfaces, or structure into multiple files.

21
Q

What is Reflection

A

Reflection is the process of describing the metadata of types, methods, and fields in a code. The namespace System. Reflection enables you to obtain data about the loaded assemblies, the elements within them like classes, methods, and value types.

22
Q

What is the difference between constant and read-only

A

In C#, a const keyword is used to declare constant fields and constant local. The value of the constant field is the same throughout the program or in other words, once the constant field is assigned the value of this field is not be changed. In C#, constant fields and locals are not variables, a constant is a number, string, null reference, boolean values. readonly keyword is used to declare a readonly variable. This readonly keyword shows that you can assign the variable only when you declare a variable or in a constructor of the same class in which it is declared.

23
Q

What are jagged arrays

A

A jagged array is an array of arrays such that member arrays can be of different sizes. In other words, the length of each array index can differ. The elements of Jagged Array are reference types and initialized to null by default. Jagged Array can also be mixed with multidimensional arrays. Here, the number of rows will be fixed at the declaration time, but you can vary the number of columns.

24
Q

What is System.Array.CopyTo()

A

The System.Array.CopyTo() technique makes a replica of the components into another existing array. It makes copies the components of one cluster to another existing array.

25
Q

What is System.Array.Clone()

A

The Clone() technique returns a new array object containing every one of the components in the first array. The Clone() makes a duplicate of an array as an object, consequently should be cast to the real exhibit type before it tends to be utilized to do definitely. The clone is of a similar type as the first Array.

26
Q

What are delegates in C#

A

A delegate is an object which refers to a method, or you can say it is a reference type variable that can hold a reference to the methods. Delegates in C# are similar to the function pointer in C/C++. It provides a way that tells which method is to be called when an event is triggered. For example, if you click a button on a form (Windows Form application), the program would call a specific method. In simple words, it is a type that represents references to methods with a particular parameter list and return type and then calls the method in a program for execution when it is needed.

27
Q

What is the sealed keyword

A

Sealed classes are used to restrict the users from inheriting the class. A class can be sealed by using the sealed keyword. The keyword tells the compiler that the class is sealed, and therefore, cannot be extended. No class can be derived from a sealed class.

A method can also be sealed, and in that case, the method cannot be overridden. However, a method can be sealed in the classes in which they have been inherited. If you want to declare a method as sealed, then it has to be declared as virtual in its base class.

28
Q

What is constructor chaining

A

We can call an overloaded constructor from another constructor using this keyword but the constructor must belong to the same class because this keyword is pointing to the members of the same class in which this is used. This type of calling the overloaded constructor is also termed as Constructor Chaining.

29
Q

What is multicasting

A

Multicasting of delegate is an extension of the normal delegate(sometimes termed as Single Cast Delegate). It helps the user to point more than one method in a single call.

30
Q

Can multiple catch blocks be executed?

A

Multiple catch blocks of the same type cannot be executed. Once the proper catch code is executed, the control is transferred to the finally block, and then the code that follows the finally block gets executed.

Generally, multiple catch block is used to handle different types of exceptions means each catch block is used to handle different type of exception.

31
Q

What is public

A

Public declared variables or methods are accessible anywhere in the application.

32
Q

What is static

A

Static declared variables or methods are globally accessible without creating an instance of the class. Static member are by default not globally accessible it depends upon the type of access modified used. The compiler stores the address of the method as the entry point and uses this information to begin execution before any objects are created.

33
Q

What is void

A

Void is a type modifier that states that the method or variable does not return any value.

34
Q

What is the difference between Array and ArrayList

A

In an array, we can have items of the same type only. The size of the array is fixed when compared. To an arraylist is similar to an array, but it doesn’t have a fixed size.

35
Q

Can a private virtual method be overriden

A

No, because they are not accessible outside the class.

36
Q

Describe the accessibility modifier “protected internal”

A

Protected Internal variables/methods are accessible within the same assembly and also from the classes that are derived from this parent class.

37
Q

What are the differences between System.String and System.Text.StringBuilder

A

System.String is immutable. When we modify the value of a string variable, then a new memory is allocated to the new value and the previous memory allocation released. System.StringBuilder was designed to have a concept of a mutable string where a variety of operations can be performed without allocation separate memory location for the modified string.

38
Q

How can we sort the elements of the Array in descending order

A

Using Sort() methods followed by Reverse() method.

39
Q

Syntax to catch an exception

A
try {
    GetAllData();
} 
catch (Exception ex) {
}
40
Q

What are generics in C# .NET

A

Generics are used to make reusable code classes to decrease the code redundancy, increase type safety, and performance. Using generics, we can create collection classes. To create generic collection, System.Collections.Generic namespace should be used instead of classes such as ArrayList in the System.Collections namespace. Generics promotes the usage of parameterized types.

41
Q

What is an object pool in .NET

A

An object pool is a container having objects ready to be used. It tracks the object that is currently in use, total number of objects in the pool. This reduces the overhead of creating and re-creating objects.

42
Q

List down the commonly used types of exceptions in .NET

A

ArgumentException, ArgumentNullException, ArgumentOutOfRangeException, ArithmeticException, DivideByZeroException ,OverflowException, IndexOutOfRangeException, InvalidCastException, InvalidOperationException, IOEndOfStreamException , NullReferenceException, OutOfMemoryException, StackOverflowException etc.

43
Q

What are custom exceptions

A

Sometimes there are some errors that need to be handled as per user requirements. Custom exceptions are used for them and are used defined exceptions.

44
Q

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

A

“Throw” statement preserves original error stack whereas “throw ex” have the stack trace from their throw point. It is always advised to use “throw” because it provides more accurate error information.