.NET 3.5 4. (, btw, msvcrt.dll - Runtime Microsft ++). , .
, "4", :
class Test
{
public unsafe static void Main(string[] args)
{
byte[] bytes = new byte[] {70, 40, 30, 51, 0};
fixed(byte* ptr = bytes)
{
int len = strlen(ptr);
Console.WriteLine(len);
}
}
[DllImport("msvcrt.dll")]
private unsafe static extern int strlen(byte* pByte);
}
, - strlen , , , . , , :
private static int managed_strlen(byte[] bytes)
{
return bytes.TakeWhile(b => b != 0).Count();
}
Of course, this does not apply to multibyte (unicode) characters, but I don't think strlen is either.
driis source
share