C# ref实例讲解

时间:2022-07-23
本文章向大家介绍C# ref实例讲解,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

ref:

C#有两种参数传递方式:传值和引用,传值就是变量的值,而引用则是传递的变量的地址;

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

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 10;
            sumd(ref a);
            Console.WriteLine(a);
            Console.ReadKey();
        }

        static void sumd(ref int b)
        {
            b = b* b;
            
        }
    }
}

运行结果: 你猜猜是什么? 10么

no no no