Fórum Pointer, PChar em cSharp #607683
23/01/2020
0
Bom dia a todos! Será que alguém poderia me ajudar a converter para C#?
var
texto: string;
buffer: pointer;
begin
texto := ''''AAAAAAA'''';
buffer := PChar(texto);
end;
var
texto: string;
buffer: pointer;
begin
texto := ''''AAAAAAA'''';
buffer := PChar(texto);
end;
Fernando Ito
Curtir tópico
+ 0
Responder
Posts
11/06/2025
Anderson Gonçalves
Bom dia a todos! Será que alguém poderia me ajudar a converter para C#?
var
texto: string;
buffer: pointer;
begin
texto := ''''AAAAAAA'''';
buffer := PChar(texto);
end;
var
texto: string;
buffer: pointer;
begin
texto := ''''AAAAAAA'''';
buffer := PChar(texto);
end;
Se você só quer acessar os bytes/caracteres faça assim:
string texto = "'AAAAAAA'";
char[] buffer = texto.ToCharArray();
Já aqui é o modo com ponteiro (unsafe, semelhante ao Delphi com PChar), ai você tem que fazer assim:
using System;
class Program
{
unsafe static void Main()
{
string texto = "'AAAAAAA'";
fixed (char* buffer = texto)
{
Console.WriteLine("Texto via ponteiro:");
for (int i = 0; buffer[i] != '\\0'; i++)
{
Console.Write(buffer[i]);
}
}
Console.WriteLine();
}
}
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)