unsafe关键字

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Dynamic;
using System.ComponentModel;
using System.Diagnostics; namespace ConsoleApplication
{
public struct MyStruct
{
public int a;
public int b;
} class Program
{
static unsafe void Main(string[] args)
{
MyStruct ms = new MyStruct();
//获取MyStruct的首地址
Console.WriteLine((uint)&ms);
//获取值类型的大小
Console.WriteLine(sizeof(MyStruct));
//在堆栈上分配内存空间
int* p = stackalloc int[];
*p = ;
Console.WriteLine("*p={0}", *p);
Console.ReadLine();
} }
}

C#编译器提供了/unsafe开关来控制是否允许对unsafe关键字的代码进行编译

unsafe关键字

上一篇:CSS字体属性案例


下一篇:【Android】将Xamarin For VS升级为4.0.1.145版