C#基础-out与ref字段_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > C#基础-out与ref字段

C#基础-out与ref字段

 2016/7/30 5:32:58  airforce094  程序员俱乐部  我要评论(0)
  • 摘要:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication2{classProgram{staticvoidMain(string[]args){stringoutString="ThisistheoutStringvalue";Console.WriteLine(outString);boolok=outMethod(outoutString
  • 标签:C#
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;
        }
    }
}

 

发表评论
用户名: 匿名