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:



No comments:

Post a Comment