"Mutation of Marshalled Strings (C# Side)"

// C#
 
[DllImport(NATIVE_DLL_NAME, CallingConvention = CallingConvention.Cdecl,
    EntryPoint = "StringMutationExample")]
public static extern void StringMutationExample(
    [MarshalAs(InteropUtils.INTEROP_STRING_TYPE)] string myString
);
 
public static void Test() {
    string myString = "Yolo";
    StringMutationExample(myString);
    Console.WriteLine(myString); // Prints 'Rolo' to the console!
}


Code snippet taken from "P/Invoke Tips".