现在的位置: 首页 > 综合 > 正文

C# 解释ref和out参数中out参数适用于“返回多个值的情况”,这句话的意思

2013年02月13日 ⁄ 综合 ⁄ 共 636字 ⁄ 字号 评论关闭

看了网上的许多资料,懂得了out和ref参数的用法和语法,out和ref语法,在此不再赘述。

这里只解释一下什么叫做:返回多个值。(小弟正在入门,有什么不对的地方,大家一定指正,谢谢)

using System;

namespace TestOutref
{

    class testapp
    {
        static void testOut(out int a, out int b, out string c, out bool d)
        {
            a = 1;
            b = 2;
            c = "我是第三个参数";
            d = true;
        }
        public static void Main()
        {
            int a, b;
            string c;
            bool d;

            testOut(out a, out b, out c, out d);
            //经过执行方法testOut(),相当于返回了a,b,c,d四个参数,也就是说out适合用于返回多个参数的情况

            Console.Write("{0},{1},{2},{3}", a, b, c, d.ToString());
            Console.Read();

        }
    }

}

ps:琢磨了半天才弄懂“返回多个值”,暂时理解就这么个意思吧,也不知道对不对,望指正,谢谢啊

抱歉!评论已关闭.