Difference between C# ref out keyword

The C# ref keyword is used almost the same as the C++ & (reference) keyword.

The C# out keyword works similarly to ref. The difference is that the data will be forced to be emptied when entering the callee.

        public void f1(out Data d1)
        {
            d1 = new Data(); // If you don't renew, you can't compile 
            d1.m = 99 ;
            d1.n = 99;
        }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324840927&siteId=291194637