Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

out (C# Reference)

  • 2024-03-30
Feedback

In this article

You can use theout keyword in two contexts:

Theout keyword is especially useful when a method needs to return more than one value since more than oneout parameter can be used e.g.

    public void Main()    {        double radiusValue = 3.92781;        //Calculate the circumference and area of a circle, returning the results to Main().        CalculateCircumferenceAndArea(radiusValue, out double circumferenceResult, out var areaResult);        System.Console.WriteLine($"Circumference of a circle with a radius of {radiusValue} is {circumferenceResult}.");        System.Console.WriteLine($"Area of a circle with a radius of {radiusValue} is {areaResult}.");        Console.ReadLine();    }    //The calculation worker method.    public static void CalculateCircumferenceAndArea(double radius, out double circumference, out double area)    {        circumference = 2 * Math.PI * radius;        area = Math.PI * (radius * radius);    }

The following limitations apply to using theout keyword:

  • out parameters are not allowed in asynchronous methods.
  • out parameters are not allowed in iterator methods.
  • Properties cannot be passed asout parameters.
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo