码迷,mamicode.com
首页 > Windows程序 > 详细

C#基础-out与ref字段

时间:2016-07-29 22:46:20      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:

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;
        }
    }
}

 

C#基础-out与ref字段

标签:

原文地址:http://www.cnblogs.com/lovecsharp094/p/5719761.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!