当前位置:网站首页>C method parameter: in

C method parameter: in

2022-06-13 03:07:00 cathy18c

Method parameter in Can only read , Cannot modify within a method , It and ref It also needs to be initialized as an argument , And the same as ref equally , Whether you define a method or call a method, you need to add in keyword .

class Program
    {
        static void Add(in int num1)
        {
            num1++; //  This place reported a mistake , Tips in num1 It's a read-only variable 
            Console.WriteLine("Add In the way num1 The value of is :{0}", num1);
        }

        static void Main(string[] args)
        {            
            int num1=0;
            Add(in num1);
            Console.WriteLine("Main In the way num1 The value of is :{0}",num1);
        }        
    }

in It's worth passing on , Is the default delivery , Even if you don't write in The default is in 

Parameters :in Parameter modifiers

原网站

版权声明
本文为[cathy18c]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280534095308.html