Created
July 16, 2015 23:32
-
-
Save Fhernd/adb1a25ad6624b21c299 to your computer and use it in GitHub Desktop.
Demostración de uso de fixed para bloques de memoria.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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