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
Explain type in C#
Anonymous types allow us to create a new type without defining them. This is way to defining read only properties into a single object without having to define type explicitly. Here Type is generating by the compiler and it is accessible only for the current block of code. The type of properties is also inferred by the compiler.
Anonymous types allow us to create a new type without defining them. This is way to defining read only properties into a single object without having to define type explicitly. Here Type is generating by the compiler and it is accessible only for the current block of code. The type of properties is also inferred by the compiler.
What will be the output of the following code snippet?
Anonymous Quiz
75%
0 1 2 3 4 5 6 7 8 9
11%
32333435363738394041
14%
Compile time Error
What will be the output of the following code snippet?
Anonymous Quiz
32%
True
59%
False
7%
Compilation error
2%
Error
What is scope of a Internal member variable of a C# class?
Internal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly. In other words, any member with internal access specifier can be accessed from any class or method defined within the application in which the member is defined.
You can use it for utility or helper classes/methods that you would like to access from many other classes within the same assembly, but that you want to ensure code in other assemblies can't access.
Internal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly. In other words, any member with internal access specifier can be accessed from any class or method defined within the application in which the member is defined.
You can use it for utility or helper classes/methods that you would like to access from many other classes within the same assembly, but that you want to ensure code in other assemblies can't access.
What will be the output of the following code snippet?
Anonymous Quiz
55%
Object argument
10%
double array argument
6%
Object argument, double array argument
29%
The Program compiles successfully but nothing gets printed
I've noticed there were only 7% of correct answers (🎉) on the last tricky question (I was also confused 🤡)
Let me explain why it happens.
C# specification: https://www.ecma-international.org/wp-content/uploads/ECMA-334_5th_edition_december_2017.pdf
Let me explain why it happens.
C# specification: https://www.ecma-international.org/wp-content/uploads/ECMA-334_5th_edition_december_2017.pdf
📝 What is deep or shallow copy concept in C#?
🔸 Shallow Copy is about copying an object's value type fields into the target object and the object's reference types are copied as references into the target object but not the referenced object itself. It copies the types bit by bit. The result is that both instances are cloned and the original will refer to the same object.
🔸 Deep Copy is used to make a complete deep copy of the internal reference types, for this we need to configure the object returned by
In other words a deep copy occurs when an object is copied along with the objects to which it refers.
#post
🔸 Shallow Copy is about copying an object's value type fields into the target object and the object's reference types are copied as references into the target object but not the referenced object itself. It copies the types bit by bit. The result is that both instances are cloned and the original will refer to the same object.
🔸 Deep Copy is used to make a complete deep copy of the internal reference types, for this we need to configure the object returned by
MemberwiseClone()
.In other words a deep copy occurs when an object is copied along with the objects to which it refers.
#post
📝 What is Extension Method in C# and how to use them?
Extension methods allow you to add methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. An extension method is a special kind of static method, but they are called as if they were instance methods on the extended type.
Extension methods allow you to add methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. An extension method is a special kind of static method, but they are called as if they were instance methods on the extended type.
📝 What is sealed Class in C#?
When applied to a class, the sealed modifier prevents other classes from inheriting from it. In the following example, class B inherits from class A, but no class can inherit from class B.
You can also use the sealed modifier on a method or property that overrides a virtual method or property in a base class. This enables you to allow classes to derive from your class and prevent them from overriding specific virtual methods or properties.
Summary:
🔸 Once a class is defined as a sealed class, the class cannot be inherited.
🔸 Structs are also sealed.
When applied to a class, the sealed modifier prevents other classes from inheriting from it. In the following example, class B inherits from class A, but no class can inherit from class B.
You can also use the sealed modifier on a method or property that overrides a virtual method or property in a base class. This enables you to allow classes to derive from your class and prevent them from overriding specific virtual methods or properties.
Summary:
🔸 Once a class is defined as a sealed class, the class cannot be inherited.
🔸 Structs are also sealed.
📝 Why to use of the IDisposable interface?
The "primary" use of the IDisposable interface is to clean up unmanaged resources. Note the purpose of the Dispose pattern is to provide a mechanism to clean up both managed and unmanaged resources and when that occurs depends on how the Dispose method is being called.
The "primary" use of the IDisposable interface is to clean up unmanaged resources. Note the purpose of the Dispose pattern is to provide a mechanism to clean up both managed and unmanaged resources and when that occurs depends on how the Dispose method is being called.
📝 Explain the difference between Task and Thread in .NET
🔸 Thread represents an actual OS-level thread, with its own stack and kernel resources. Thread allows the highest degree of control; you can Abort() or Suspend() or Resume() a thread, you can observe its state, and you can set thread-level properties like the stack size, apartment state, or culture. ThreadPool is a wrapper around a pool of threads maintained by the CLR.
🔸 The Task class from the Task Parallel Library offers the best of both worlds. Like the ThreadPool, a task does not create its own OS thread. Instead, tasks are executed by a TaskScheduler; the default scheduler simply runs on the ThreadPool. Unlike the ThreadPool, Task also allows you to find out when it finishes, and (via the generic Task) to return a result.
🔸 Thread represents an actual OS-level thread, with its own stack and kernel resources. Thread allows the highest degree of control; you can Abort() or Suspend() or Resume() a thread, you can observe its state, and you can set thread-level properties like the stack size, apartment state, or culture. ThreadPool is a wrapper around a pool of threads maintained by the CLR.
🔸 The Task class from the Task Parallel Library offers the best of both worlds. Like the ThreadPool, a task does not create its own OS thread. Instead, tasks are executed by a TaskScheduler; the default scheduler simply runs on the ThreadPool. Unlike the ThreadPool, Task also allows you to find out when it finishes, and (via the generic Task) to return a result.