- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
using System;
class program
{
unsafe public static void Foo(int* pa)
{
for (int* ip = pa; ip < (pa+5); ip++)
{
Console.WriteLine("value {0} at address: {1}", *ip, (int)ip);
}
}
static void Main(string[] args)
{
unsafe
{
int* pa = stackalloc int[5];
pa[0] = 12;
pa[1] = 34;
pa[2] = 56;
pa[3] = 78;
pa[4] = 90;
Foo(pa);
}
}
}
Inside C#, Tom Archer, Andrew Whitechapel, 912 Pages
Copyright © 2002 by Microsoft Corporation
Part III, Chapter 20, "168 Pinning"
"Notice that we don't take the address of ia, just its value, because its value is really the address of the int at the beginning of the array. Recall that although ints are value types, arrays (including arrays of ints) are reference types and are allocated on the heap. Just as we had to fix the address of a value-type member of a reference-type object, we also have to fix the address of a value-type element in a (reference-type) array. Let's put this together in a test application:"
Надеюсь, тождественность доказывать не надо?
Вот ещё кусок.
P.S. Анонимус умеет гуглить.
P.P.S. Анонимус не прощает.
Да вы батенька Луркоёб.
ананистус