3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

unsafeとfixed

Posted at

c#でポインター(unsafeコード)を使う場合は、オブジェクトが使用しているメモリが移動しないように fixed を使用する必要がある。

unsafeとfixed
using System;

class Test {
	public int num;
	public Test(int i) { num = i; }
}

class UseFixed {
	unsafe static void Main() {
		Test o = new Test (19);
		fixed (int *p = &o.num) {
			Console.WriteLine("Initial value of o.num is " + *p);
			*p = 10;
			Console.WriteLine("New value of o.num is " + *p);
		}
	}
}
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?