Search This Blog

Q61-Q65

Q61. Difference between Ref and Out keywords?
Q62. What are the differences between Application object and session object?
Q63. What is the difference between .tostring(), Convert.tostring()?
Q64. What is the difference between func action and predicate delegates?
Q65. Difference between covariance and variance in delegates?
-----------------------------------------------------------------------------------------------------------------------------
Q61. Difference between Ref and Out keywords?

Answer:
Both ref and out are technique to get values when we have more than one return type. Both ref and out pass value by reference. 
Ref need to be initialized before usage while Out can be used without initializing it. 

        static void Main(string[] args)
        {
            int i;
            int j;
            j = 9;
            string s = getstring(out i, ref j);
            Console.WriteLine(i);
            Console.WriteLine(j);
            Console.Read();
                    }

        private static string getstring(out int i, ref int j)
        {
            j = 6;
            i = 4;
            return "app";
        }
-----------------------------------------------------------------------------------------------------------------------------
Q62. What are the differences between Application object and session object?

Answer:
The session object is used to maintain the session of each user. If one user enter in to the application then they get session id if he leaves from the application then the session id is deleted. If they again enter in to the application they get different session id.
But for application object the id is maintained for whole application.

-----------------------------------------------------------------------------------------------------------------------------
Q63. What is the difference between .tostring(), Convert.tostring()?

Answer:
The basic difference between them is “Convert” function handles NULLS while
“.ToString()” does not it will throw a NULL reference exception error. So as a good coding practice using “convert” is always safe.
-----------------------------------------------------------------------------------------------------------------------------
Q64. What is the difference between func action and predicate delegate?

Answer:
1) The Func delegate takes zero, one or more input parameters, and returns a value (with its out parameter).

2) Action takes zero, one or more input parameters, but does not return anything.

3) Predicate is a special kind of Func. It represents a method that contains a set of criteria mostly defined inside an if condition and checks whether the passed parameter meets those criteria or not.

-----------------------------------------------------------------------------------------------------------------------------
Q65. Difference between covariance and variance in delegates?

Answer:



Q56-Q60

Q56. What is the difference between .net Standard, .net Framework and .net Core?
Q57. What are four pillars of OOPS? Explain Abstraction and Encapsulation in detail?
Q58. What is the difference between Array and Collection?
Q59. What are the two ways to prevent class from being inherited?
Q60. What is jagged Array?
-----------------------------------------------------------------------------------------------------------------------------
Q56. What is the difference between .net Standard, .net Framework and .net Core?

Answer:

-----------------------------------------------------------------------------------------------------------------------------
Q57. What are four pillars of OOPS? Explain Abstraction and Encapsulation in detail?

Answer:
Abstraction, Encapsulation, Polymorphism, and inheritance are called 4 pillars of OOPS. 

Encapsulation - Binding or encapsulating of all related data into a single unit and keep it safe from outside misuse and access. Class is an example of encapsulation. We can methods private, protected and public to protect the misuse from outside code. 

Abstraction - It means showing only the relevant information hiding the unnecessary complexity. Abstraction can be implemented by use of interface and abstract class.  By use of Interface we are telling client only the method name, parameters required and output we will receive. 
-----------------------------------------------------------------------------------------------------------------------------
Q58. What is the difference between Array and Collection?

Answer:

Difference between Array and Collection:
 
ArrayCollection
1. Array is Group of Homogeneous data type object.1. Collection is Group of Homogeneous and Heterogeneous data type object.
2. Array is fixed in size.2. Collection is not fixed in size.
3. Array is Strong type.3. Collection is not strong Type.
4. There is no boxing and unboxing process on Array4. There is process of Boxing and Unboxing on Collection.
 5.We use Generic on Collection to make Collection as Strong type

Heterogeneous collection example - ArrayList a = new ArrayList()
collections examples - ArrayList, List, Stack, ICollection, IEnumerableand IDictionary. 


-----------------------------------------------------------------------------------------------------------------------------
Q59. What are the two ways to prevent class from being inherited?

Answer:
1. Make class sealed
2. Make class constructor private. 

-----------------------------------------------------------------------------------------------------------------------------
Q60. What is jagged Array?

Answer:
Array of Array is known as jagged array. 

Below is the example of jagged Array. 

int[][] jaggedArray = new int[3][];

jaggedArray[0] = new int[5];
jaggedArray[1] = new int[4];
jaggedArray[2] = new int[2];

Q51-Q55

Q51. What is the difference between for loop and Foreach loop in C#? Which has better performance and why?
Q52. When to choose readonly and when to choose constant?
Q53. Good coding practices in C#?
Q54. What is cyclomatic complexity in programming?
Q55. What is Big O notation?

=======================================================================================
Q51. What is the difference between for loop and Foreach loop in C#? Which has better performance and why?

Answer:
For loop is just a iteration loop and can be used for anything while foreach loop is only designed to work on collections. 

Performance or speed wise for loop is almost similar to ForEach loop but theoretically for loop is better in performance. 
=======================================================================================
Q52. When to choose readonly and when to choose constant?

Answer:
When you want to make something static during compile time and you do not want this value get hampered anywhere in code make it Constant. 

Constants are static by default. Constant give better performance as they are defined in memory at compile time only. 

Readonly are required when you have your constants at run time only for eg. you get something related to claims during run time from the client whom initializes the class and once you have the data you do not want it to get changed in future than you can use read-only. 

Readonly has a little overhead of getting value during run time but has advantage of defining value at run time which is not possible in case of Constant. 

=======================================================================================
Q53. Good coding practices in C#?

Answer:
1. Code must have proper error handling. 
2. Proper logging
3. Good coding practices tool like Sonar must be integrated. 
4. Good naming convention must be used. 
5. Proper comments must be present. 
6. Null, empty, undefined check must be present where ever possible. 
7. While comparing string either bring both string into lowercase or into upper case.
8. Make proper usage of access modifiers. We must not make blindly everything public. 
9. Make use of Interface as it bring dependency injection in picture. 
10. When working on un managed code, we must remember to dispose un managed code. 
11. Make use of authentication filter or middleware

=======================================================================================
Q54. What is cyclomatic complexity in programming?

Answer:
software metric used to determine the complexity of a program. It is a count of the number of decisions in the source code. The higher the count, the more complex the code.
IF-else, is a great example of this. 

=======================================================================================
Q55. What is Big O  notation?

Answer:

Big O notation shows the number of operations

O(log n) Binary search
O(n) Simple search
O(n * log n) Quicksort
O(n2) Selection sort
O(n!) Traveling salesperson