crackyourinterview.com


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


Explain out keyword in c#
Question Posted on 29 Apr 2020Home >> DotNet >> C# >> Explain out keyword in c#

Explain out keyword in c#
When we talk about out keyword in c# it is basicaly used to pass arguments to method as a reference type. The out parameter in c# is useful to return more than one value from the methods in c#. We can use out keyword with variables and method parameters. Out parameter is always passed by reference for both value type and reference type data types.

Additional Features
Below are the 3 more features of c# out parameter
(1)We will no need to initialize parameters before it pass to out.
(2)We need to initialize the value of a parameter before returning to the calling method.
(3)It is not necessary that Out parameter name should be same in both function definition and call.

Declare of c# Parameter
Below is the simple example of using out parameters in c# language
  int x,y;
  multiply(out x, out y);

As in above declartion we have declared a variable x,y and pass it to method by using out parameter but not assign any value . And value is be initialized in called method before it return a value in calling method. Both the method definition and the calling method must explicitly use the out keyword.

Complete Example of out keyword
using System;
namespace Testoutkeyword
{
 class Program
 {
  static void Main(string[] args)
  {
    int x, y;
    multiply(out x, out y);
    Console.WriteLine("Value of x : {0}", x);
    Console.WriteLine("Value of y : {0}", y);
    Console.ReadLine();
  }
  public static void multiply(out int a, out int b)
  {
    a = 20;
    b = 10;
    a *= a;
    b *= b;
  }
 }
}


OutPut of Above is
Value of X : 400
Value of Y : 100
0
0




.


Most Visited Questions:-

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

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

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

Continuous Integration Questions Answers
Below are the 20 odd questions for CI or Continuous Integra 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