ref and out keyword in c#

Out keyword in C#

In Out key, When we passed variables as out arguments that time we initialized to the variables within the methods. It is also known as output parameter.
  1. Initialized must be inside the methods. 
  2. Before calling the methods may be initialized or not initialized the values of the variables.
A simple code sample as given below

public class OutClass
    static void Method(out int i)
        i = 10;
    static void Main()
        int value;
        Method(out value);

Some important notes as given below

  1. The ref and out keywords are treated differently at run-time but they are treated the same at compile time. 
  2. Methods cannot be overloaded if one method takes a ref keyword and the other takes an out keyword.


Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
Post a Comment Powered by Blogger.
ASK Questions