What will be the output of the following code snippet?
Anonymous Quiz
18%
1 0
32%
1 1
25%
0 1
25%
0 0
What are Reference Types in C#?
The reference types do not contain the actual data stored in a variable, but they contain a reference to the variables.
In other words, they refer to a memory location. Using multiple variables, the reference types can refer to a memory location. If the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value. Example of built-in reference types are: object, dynamic, and string.
The reference types do not contain the actual data stored in a variable, but they contain a reference to the variables.
In other words, they refer to a memory location. Using multiple variables, the reference types can refer to a memory location. If the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value. Example of built-in reference types are: object, dynamic, and string.
What will be the output of the following code snippet?
Anonymous Quiz
16%
4, 11
76%
1, 11
2%
4, 7
6%
1, 7
What is the volatile keyword used for?
In C# volatile tells the compiler that the value of a variable must never be cached as its value may change outside of the scope of the program itself (such as the operating system, the hardware, or a concurrently executing thread). The compiler will then avoid any optimisations that may result in problems if the variable changes "outside of its control".
Or in more simple terms:
Sometimes, the compiler will optimize a field and use a register to store it. If thread 1 does a write to the field and another thread accesses it, since the update was stored in a register (and not memory), the 2nd thread would get stale data.
You can think of the volatile keyword as saying to the compiler "I want you to store this value in memory". This guarantees that the 2nd thread retrieves the latest value.
In C# volatile tells the compiler that the value of a variable must never be cached as its value may change outside of the scope of the program itself (such as the operating system, the hardware, or a concurrently executing thread). The compiler will then avoid any optimisations that may result in problems if the variable changes "outside of its control".
Or in more simple terms:
Sometimes, the compiler will optimize a field and use a register to store it. If thread 1 does a write to the field and another thread accesses it, since the update was stored in a register (and not memory), the 2nd thread would get stale data.
You can think of the volatile keyword as saying to the compiler "I want you to store this value in memory". This guarantees that the 2nd thread retrieves the latest value.
What is Managed or Unmanaged Code?
🔸 Managed Code - The code, which is developed in .NET framework is known as managed code. This code is directly executed by CLR with the help of managed code execution. Any language that is written in .NET Framework is managed code.
🔸 Unmanaged Code - The code, which is developed outside .NET framework is known as unmanaged code. Applications that do not run under the control of the CLR are said to be unmanaged, and certain languages such as C++ can be used to write such applications, which, for example, access low - level functions of the operating system. Background compatibility with the code of VB, ASP and COM are examples of unmanaged code.
🔸 Managed Code - The code, which is developed in .NET framework is known as managed code. This code is directly executed by CLR with the help of managed code execution. Any language that is written in .NET Framework is managed code.
🔸 Unmanaged Code - The code, which is developed outside .NET framework is known as unmanaged code. Applications that do not run under the control of the CLR are said to be unmanaged, and certain languages such as C++ can be used to write such applications, which, for example, access low - level functions of the operating system. Background compatibility with the code of VB, ASP and COM are examples of unmanaged code.
What will be the output of the following code snippet?
Anonymous Quiz
50%
Welcome Readers, To the World of C# !!
41%
Welcome Readers
4%
ThreadAbortException
4%
Program compiles successfully and nothing is printed
What is the use of static constructors?
A static constructor is useful for initializing any static fields associated with a type (or any other per-type operations) - useful in particular for reading required configuration data into readonly fields, etc.
It is run automatically by the runtime the first time it is needed (the exact rules there are complicated (see "beforefieldinit"), and changed subtly between CLR2 and CLR4). Unless you abuse reflection, it is guaranteed to run at most once (even if two threads arrive at the same time).
You can't overload it.
A static constructor is useful for initializing any static fields associated with a type (or any other per-type operations) - useful in particular for reading required configuration data into readonly fields, etc.
It is run automatically by the runtime the first time it is needed (the exact rules there are complicated (see "beforefieldinit"), and changed subtly between CLR2 and CLR4). Unless you abuse reflection, it is guaranteed to run at most once (even if two threads arrive at the same time).
You can't overload it.
Can this be used within a Static method?
We can't use this in static method because keyword this returns a reference to the current instance of the class containing it.
Static methods (or any static member) do not belong to a particular instance. They exist without creating an instance of the class and call with the name of a class not by instance so we can't use this keyword in the body of static Methods, but in case of Extension Methods we can use it as the functions parameters.
We can't use this in static method because keyword this returns a reference to the current instance of the class containing it.
Static methods (or any static member) do not belong to a particular instance. They exist without creating an instance of the class and call with the name of a class not by instance so we can't use this keyword in the body of static Methods, but in case of Extension Methods we can use it as the functions parameters.
What will be the output of the following code snippet?
Anonymous Quiz
48%
Class Executed, Interface Executed
41%
Class Executed
6%
Interface Executed
5%
NullReferenceException
What is a preprocessor directives in C#?
The preprocessor directives give instruction to the compiler to preprocess the information before actual compilation starts. Generally, the optional/conditional compilation symbols will be provided by the build script.
Not only is this cleaner and easier to read since you don't end up having #if, #else within your code. This style is less prone to errors either during normal code edits and well as logic flow errors.
The preprocessor directives give instruction to the compiler to preprocess the information before actual compilation starts. Generally, the optional/conditional compilation symbols will be provided by the build script.
Not only is this cleaner and easier to read since you don't end up having #if, #else within your code. This style is less prone to errors either during normal code edits and well as logic flow errors.
What is enum in C#?
An enum is a value type with a set of related named constants often referred to as an enumerator list. The enum keyword is used to declare an enumeration. It is a primitive data type, which is user defined. An enum is used to create numeric constants in .NET framework. All the members of enum are of enum type. Their must be a numeric value for each enum type.
Some points about enum:
🔸 Enums are enumerated data type in C#.
🔸 Enums are strongly typed constant. They are strongly typed, i.e. an enum of one type may not be implicitly assigned to an enum of another type even though the underlying value of their members are the same.
🔸 Enumerations (enums) make your code much more readable and understandable.
🔸 Enum values are fixed. Enum can be displayed as a string and processed as an integer.
🔸 The default type is int, and the approved types are byte, sbyte, short, ushort, uint, long, and ulong.
🔸 Enums are value types and are created on the stack and not on the heap.
An enum is a value type with a set of related named constants often referred to as an enumerator list. The enum keyword is used to declare an enumeration. It is a primitive data type, which is user defined. An enum is used to create numeric constants in .NET framework. All the members of enum are of enum type. Their must be a numeric value for each enum type.
Some points about enum:
🔸 Enums are enumerated data type in C#.
🔸 Enums are strongly typed constant. They are strongly typed, i.e. an enum of one type may not be implicitly assigned to an enum of another type even though the underlying value of their members are the same.
🔸 Enumerations (enums) make your code much more readable and understandable.
🔸 Enum values are fixed. Enum can be displayed as a string and processed as an integer.
🔸 The default type is int, and the approved types are byte, sbyte, short, ushort, uint, long, and ulong.
🔸 Enums are value types and are created on the stack and not on the heap.
What will be the output of the following code snippet?
Anonymous Quiz
59%
Compile error
20%
-2
9%
2
12%
0
List some different ways for equality check in .NET
🔸 The ReferenceEquals() method - checks if two reference type variables(classes, not structs) are referred to the same memory address.
🔸 The virtual Equals() method. (System.Object) - checks if two objects are equivalent.
🔸 The static Equals() method - is used to handle problems when there is a null value in the check.
🔸 The Equals method from IEquatable interface.
🔸 The comparison operator == - usually means the same as ReferenceEquals, it checks if two variables point to the same memory address. The gotcha is that this operator can be override to perform other types of checks. In strings, for instance, it checks if two different instances are equivalent.
🔸 The ReferenceEquals() method - checks if two reference type variables(classes, not structs) are referred to the same memory address.
🔸 The virtual Equals() method. (System.Object) - checks if two objects are equivalent.
🔸 The static Equals() method - is used to handle problems when there is a null value in the check.
🔸 The Equals method from IEquatable interface.
🔸 The comparison operator == - usually means the same as ReferenceEquals, it checks if two variables point to the same memory address. The gotcha is that this operator can be override to perform other types of checks. In strings, for instance, it checks if two different instances are equivalent.
In how many ways you can pass parameters to a method?
There are three ways that parameters can be passed to a method:
🔸 Value parameters − This method copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.
🔸 Reference parameters − This method copies the reference to the memory location of an argument into the formal parameter. This means that changes made to the parameter affect the argument.
🔸 Output parameters − This method helps in returning more than one value.
There are three ways that parameters can be passed to a method:
🔸 Value parameters − This method copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.
🔸 Reference parameters − This method copies the reference to the memory location of an argument into the formal parameter. This means that changes made to the parameter affect the argument.
🔸 Output parameters − This method helps in returning more than one value.
What will be the output of the following code snippet?
Anonymous Quiz
8%
Runtime Error
15%
Compile time Error
64%
Division By Zero
14%
Infinity