C# equivalent to C const char**

后端 未结 5 1199
鱼传尺愫
鱼传尺愫 2021-01-22 10:42

I want to implement a Mongoose (http://code.google.com/p/mongoose/) Binding in C#. There are some examples, but they don\'t work with the current version.

This is my cu

5条回答
  •  伪装坚强ぢ
    2021-01-22 11:24

    In C# a char is an Unicode character, therefore consisting of two bytes. Using strings is not an option here, but you can use the Encoding.ASCII class to get the ASCII representation of the unicode string as a byte array:

    byte[] asciiString = Encoding.ASCII.GetBytes(unicodeString);
    

    C#'s arrays are references, aka pointers in C, so you can write your code as:

    byte[][] options = {
        Encoding.ASCII.GetBytes("document_root"),
        Encoding.ASCII.GetBytes("/var/www"),
        Encoding.ASCII.GetBytes("listening_ports"),
        Encoding.ASCII.GetBytes("80,443s"),
        null
    };
    

    You can't do anything about the const other than creating a wrapper class with read-only indexers and a private array of bytes, but this won't work in your case.

提交回复
热议问题