char* to a string in C#

后端 未结 4 2277
北恋
北恋 2021-02-14 20:07

I\'m calling a function from a native DLL which returns a char* pointer, how can I convert the returned pointer to a string ? I tried :

char* c = f         


        
4条回答
  •  误落风尘
    2021-02-14 20:30

    public static void Main(string[] args)
            {
                var charArray = new[] {'t', 'e', 's', 't'};
                fixed (char* charPointer = charArray)
                {
                    var charString = new string(charPointer);
                }
            }
    

提交回复
热议问题