C#基础-out与ref字段

2018-06-18 04:31:34来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
       
        static void Main(string[] args)
        {
            string outString = "This is the outString value";

            Console.WriteLine(outString);

            bool ok = outMethod(out outString);

            Console.WriteLine(outString);

            Console.WriteLine(ok.ToString());


            /*我是分隔线*/
            string refString = "This is the refString value";

            Console.WriteLine(refString);

            bool okk = refMethod(ref refString);

            Console.WriteLine(refString);

            Console.WriteLine(okk.ToString());

            Console.ReadKey();

        }
        static bool outMethod(out string str)
        {
            
            str = "This is the new outString value"; //必须设值
            return true;
        }
        static bool refMethod(ref string str)
        {

            str = "This is the new outString value"; //此句可以不写,即不用重新设值
            return true;
        }
    }
}

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:VB的判断语句和循环语句

下一篇:.net弹出框