书《C#6.0学习笔记》个人笔记

完全没有看懂!

1、ref out 关键字

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

namespace ConsoleApp1
{
    class Person
    {
        public string Name
        {
            get;
            set;
        }
        public string Age
        {
            get;
            set;
        }
    }
    class Program
    {
        static void Test( Person p)
        {
            p.Name = "one";
            p.Age = "2";
        }
        static void Test1(ref Person p)
        {
            p = new Person();
            p.Name = "two";
            p.Age = "123";
        }
        static void Test2(out Person p)
        {
            p = new Person();
            p.Name = "dou";
            p.Age = "11525";
        }
        static void Main(string[] args)
        {
            Person p = new Person();
            p.Name = "lowe";
            p.Age = "123";
            Console.WriteLine("{0},{1}",p.Name,p.Age);

            Test(p);
            Console.WriteLine("{0},{1}", p.Name, p.Age);

            Test1(ref p);
            Console.WriteLine("{0},{1}", p.Name, p.Age);

            Test2(out p);
            Console.WriteLine("{0},{1}", p.Name, p.Age);
        }
    }
}

运行结果

你可能感兴趣的:(C#,6.0学习笔记)