- 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);
}
}
}
guest 08.04.2010 02:35 # +4.6
sergylens 08.04.2010 02:50 # −7
guest 08.04.2010 08:45 # +7
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. Анонимус не прощает.
guest 08.04.2010 08:16 # +4.8
sergylens 08.04.2010 12:17 # −6.6
guest 08.04.2010 13:28 # +2.2
guest 08.04.2010 15:06 # −3.4
Да вы батенька Луркоёб.
guest 08.04.2010 15:07 # −2.4
guest 08.04.2010 15:08 # 0
ананистус
guest 08.04.2010 17:58 # +3
guest 08.04.2010 15:14 # −3.4