C# return语句

一、C# return语句

return语句用于终止它出现在其中的方法的执行,并将控制返回给调用方法。

语法格式如下:

return ...;return语句还可以返回一个可选值。如果方法为void类型,则可以省略return语句。

二、示例
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
    class Program
    {
        static int a(int b)
        {
            int c = b * b;
            return c;
        }
        static void Main(string[] args)
        {
            // C# return语句-www.baike369.com
            int d = 5;
            Console.WriteLine("f = {0}", a(d));
            Console.ReadLine();
        }
    }
}

运行结果:
 
f = 25

原文地址:https://www.cnblogs.com/melao2006/p/4239366.html