Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 16, 2015 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/adb1a25ad6624b21c299 to your computer and use it in GitHub Desktop.
Save Fhernd/adb1a25ad6624b21c299 to your computer and use it in GitHub Desktop.
Demostración de uso de fixed para bloques de memoria.
// OrtizOL - xCSw - http://ortizol.blogspot.com
using System;
unsafe struct UnsafeCadenaUnicode
{
public short Longitud;
public fixed byte Bufer[30]; // Bloue de 30 bytes fijos.
}
unsafe public class Entidad
{
UnsafeCadenaUnicode cadena;
public Entidad(string s)
{
cadena.Longitud = (short)s.Length;
fixed (byte* puntero = cadena.Bufer)
{
for (int i = 0; i < s.Length; ++i)
{
puntero[i] = (byte) s[i];
}
}
}
}
public class PruebaEntidad
{
public static void Main()
{
new Entidad("John Ortiz Ordoñez");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment