开发者

Initialize sbyte** in C# unsafe context

开发者 https://www.devze.com 2023-03-21 18:33 出处:网络
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 solut

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

精彩评论

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

关注公众号