PART I
C h a p t e r 2 0 :
U n s a f e C o d e , P o i n t e r s , N u l l a b l e T y p e s , a n d M i s c e l l a n e o u s T o p i c s
589
PART IPART I
class FixedCode {
// Mark Main as unsafe.
unsafe static void Main() {
Test o = new Test(19);
fixed (int* p = &o.num) { // use fixed to put address of o.num into p
Console.WriteLine("Initial value of o.num is " + *p);
*p = 10; // assign 10 to count via p
Console.WriteLine("New value of o.num is " + *p);
}
}
}
The output from this program is shown here:
Initial value of o.num is 19
New value of o.num is 10
Here,
Do'stlaringiz bilan baham: |