crackyourinterview.com


To improves our performance please Like Share Subscribe(Will boost us)

What is Out and Ref in c# with similarity and differences
Question Posted on 29 Apr 2020Home >> DotNet >> C# >> What is Out and Ref in c# with similarity and differences

What is Out and Ref in c# with similarity and differences
Before going to difference first we learn about the similarity between out and ref. For both ref and out cannot be used in method overloading. Both are treated differently at run-time. But both of these are same at compile time. CLR will not make difference between these two but create IL for ref and out.Properties are not variables, therefore it cannot be passed as an out or ref parameter.

Ref


(1)ref is useful when we already know the parameter value and only called method can change the data.
(2)Called method has no responsibility to initialize parameter.
(3)In ref we have option to pass data in both directions like parent to child and child to parent method.
(4)ref will not be used to return multiple values from method.
(5)We have option to called method must work for ref parameter or not we have a option here.
(6)public void myTestFunction(ref MyClass someClass)

Out


(1)out is useful when we donot have the parameter value before calling the method.
(2)Called method has responsibility to initialize the parameter.
(3)In out we have to pass data only in one direction like child to parent method.
(4)out is used for retur multiple values from method.
(5)Here called method must work on out parameter and before returning it must be initialize the parameter.
(6)public void myTestFunction(out MyClass someClass)
0
0



.


Most Visited Questions:-

Deep Learning Questions Answers
Below are the different Deep Leaning Questions and answer a More...

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra More...

Derived relationships in Association Rule Mining are represented in the form of __________.
Derived relationships in Association Rule Mining are repres More...

What is Gulpjs and some multiple choice questions on Gulp
Gulpjs is an open source whihc helps in building Javascript More...

Microservices Architecture Questions Answers
Below are the different questions on Microservices Architec More...




Other Important Questions

Simplest definition of partial classes and its rules?

Definition of Tuple class with some examples?

Define Race Condition in cSharp?

C#.Net Reserve Words

can we inherit private class level variables in c#






@2014-2022 Crackyourinterview (All rights reserved)
Privacy Policy - Disclaimer - Sitemap