• Domingo 19 de Mayo de 2024, 21:23

Autor Tema:  Estructura con un array de tamaño fijo  (Leído 1484 veces)

nix2008

  • Nuevo Miembro
  • *
  • Mensajes: 10
    • Ver Perfil
Estructura con un array de tamaño fijo
« en: Miércoles 7 de Octubre de 2009, 12:45 »
0
Hola a tod@s,
necesito de vuestra ayuda. Quiero una estructa la cual contenga un string de tamaño 12 fijo, pero c sharp no me permite asignarle este tamaño. estoy probando con:

[StructLayout(LayoutKind.Sequential, Pack = 1)]
    public unsafe struct TXT
    {
        public fixed char texto[5];
    }

 unsafe static void PutString(string s, char* buffer, int bufSize)
 {
   int len = s.Length;
   if(len > bufSize)
    len = bufSize;
   for(int i= 0; i<len; i++)
    buffer = s;
   for(int i= len; i<bufSize; i++)
    buffer = (char)0;
 }

unsafe private void ComboTexto_SelectedIndexChanged(object sender, EventArgs e)
 {
           switch (ComboTexto.SelectedIndex)
                    {
                        case 0:
                           TXT f;
                           PutString("LEAB", f.texto, 5);

                            for (int i = 0; i <= 5; i++)  
                            this.data_escac.texto = f.texto;
               break;
default:
                            break;

                      }
}

nix2008

  • Nuevo Miembro
  • *
  • Mensajes: 10
    • Ver Perfil
Re: Estructura con un array de tamaño fijo
« Respuesta #1 en: Miércoles 7 de Octubre de 2009, 12:46 »
0
Y obtengo el siguiente error:
You cannot use fixed size buffers contained in unfixed expressions. Try using the fixed statement.

Alguien podria ayudarme?

Muchas gracias