Where can I find information on the Get, Set and Address methods for multidimensional System.Array instances in .NET?

前端 未结 3 1499
予麋鹿
予麋鹿 2021-01-18 06:37

System.Array serves as the base class for all arrays in the Common Language Runtime (CLR). According to this article:

For each concrete array type, [t

相关标签:
3条回答
  • 2021-01-18 06:52

    Look here, specifically section 14.2 on pages 63-65

    http://download.microsoft.com/download/7/3/3/733AD403-90B2-4064-A81E-01035A7FE13C/MS%20Partition%20II.pdf

    But the takeaway, and you can tell from the IL, is that they're the getter and setter methods for dealing with arrays at the given index positions.

    • A Get method that takes a sequence of int32 arguments, one for each dimension of the array, and returns a value whose type is the element type of the array. This method is used to access a specific element of the array where the arguments specify the index into each dimension, beginning with the first, of the element to be returned.

    • A Set method that takes a sequence of int32 arguments, one for each dimension of the array, followed by a value whose type is the element type of the array. The return type of Set is void. This method is used to set a specific element of the array where the arguments specify the index into each dimension, beginning with the first, of the element to be set and the final argument specifies the value to be stored into the target element.

    • An Address method that takes a sequence of int32 arguments, one for each dimension of the array, and has a return type that is a managed pointer to the array’s element type. This method is used to return a managed pointer to a specific element of the array where the arguments specify the index into each dimension, beginning with the first, of the element whose address is to be returned.

    Edit: That's pages 63-65 using the document's page numbering. 73-75 in the actual PDF.

    0 讨论(0)
  • 2021-01-18 06:55

    I'm not sure if it will address your very specific question but a great text on the subject (among others) is CLR via C#. It gets very in-depth for many of the topics you're interested in and spends a lot of time with the disassembler looking at the inner workings of many base .NET types including arrays. Definitely worth checking out.

    0 讨论(0)
  • 2021-01-18 07:10

    To answer your second question, you don't need to create an instance to get a MethodInfo for these methods. Something like

    var mi = typeof(string).MakeArrayType(6).GetMethod("Get");
    

    will work to get the Get method for the string[,,,,,] type.

    0 讨论(0)
提交回复
热议问题