[You must know. NET] The 12th time: The puzzle of parameters---the art of passing (the next)

Source: Internet
Author: User

This article describes the following:

Passing by value and passing by reference deep theory

Ref and out comparisons

Analysis on the application of parameters

Next, go on, "The 11th time: The confusion of parameters---the art of passing (on)"

4.2 Passing by value of reference type parameters

When the passed parameter is a reference type, it is a reference to the object that is passed and manipulated, which means that the method operation can change the original object, but it is worth thinking whether the reference or the pointer itself is passed by value. Therefore, we must have a clear understanding of the following two fundamental issues:

What is the difference between a reference type parameter and a by-value pass?

How does the string type behave as a special reference type, and how does it explain the specificity of the performance when passed by value?

First of all, we start from the basic understanding of the reference type parameters by value of the nature of the transfer, simply say the object as a parameter to pass, the execution is a copy of the object address, the operation is the copy address. This is essentially the same as the value-type parameter passed by value, and is passed by value. The difference is that the value of the value type is the type instance, and the value of the reference type is the reference address. Therefore, if the argument is a reference type, in the caller code, you can change the point of reference to make the original object's point change, as shown in the example:

Passing by value of reference type parameters

// FileName    : Anytao.net.My_Must_net
// Description : The .NET what you should know of arguments.
// Release      : 2007/07/01 1.0

// Copyright   : (C)2007 Anytao.com  http://www.anytao.com

using System;

namespace Anytao.net.My_Must_net
{
     class Args
     {
         public static void Main()
         {
             ArgsByRef abf = new ArgsByRef();
             AddRef(abf);
             Console.WriteLine(abf.i);
         }

         private static void AddRef(ArgsByRef abf)
         {
             abf.i = 20;
             Console.WriteLine(abf.i);
         }

     }

     class ArgsByRef
     {
         public int i = 10;
     }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.