开发者

Initialize sbyte** in C# unsafe context

How can sbyte** be initialized in C# unsafe context?

I need

sbyte** parameters;

to be filled with three s开发者_StackOverflow中文版trings: "first", "second", "third".


Here is a possible solution using byte**. This should be compatible with sbyte** as the encoding used is ASCII and only has values to 127.

unsafe static void Main(string[] args)
{
  fixed (byte* arg0 = Encoding.ASCII.GetBytes(args[0]), 
               arg1 = Encoding.ASCII.GetBytes(args[1]), 
               arg2 = Encoding.ASCII.GetBytes(args[2]))
  {
    byte*[] arr = { arg0, arg1, arg2 };

    fixed (byte** argv = arr)
    {
      ...
    }
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜