Prakash Kumar
What is the difference between “out” and “ref” parameters in C#?
By Prakash Kumar in .NET on Oct 27 2016
  • Madan Shekar
    Nov, 2018 5

    REFThe parameter or argument must be initialized first before it is passed to ref. It is not required to assign or initialize the value of a parameter (which is passed by ref) before returning to the calling method. Passing a parameter value by Ref is useful when the called method is also needed to modify the pass parameter. It is not compulsory to initialize a parameter value before using it in a calling method. When we use REF, data can be passed bi-directionally.OUT It is not compulsory to initialize a parameter or argument before it is passed to an out.A called method is required to assign or initialize a value of a parameter (which is passed to an out) before returning to the calling method.Declaring a parameter to an out method is useful when multiple values need to be returned from a function or method.A parameter value must be initialized within the calling method before its use. When we use OUT data is passed only in a unidirectional way (from the called method to the caller method)

    • 0
  • Prakash Kumar
    Oct, 2016 27

    out” parameter can be passed to a method and it need not be initialized where as “ref” parameter has to be initialized before it is used.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS