• Viernes 29 de Marzo de 2024, 02:24

Autor Tema:  Indexadores en C#  (Leído 4597 veces)

DanielC#

  • Miembro activo
  • **
  • Mensajes: 39
  • Nacionalidad: ar
    • Ver Perfil
Indexadores en C#
« en: Martes 27 de Agosto de 2013, 22:46 »
0
Hola a todos.
En este caso les consulto 2 cosas.-
1):¿Me podrían decir si el uso de Indexadores es correcta?.-
2):¿Que estoy haciendo mal que el array no me queda ordenado.-?

Código: C#
  1. using System;
  2.  
  3. namespace IndexadoresArray
  4. {
  5.     class ProgramaApp
  6.     {
  7.         static void Main(string[] argumentos)
  8.         {
  9.             Entorno _Entorno = new Entorno();
  10.             _Entorno._entorno();
  11.            
  12.             Datos _datos = new Datos();
  13.             _datos._Datos();
  14.  
  15.             Console.Write("\n\n Pulse una tecla para cerrar la aplicación...");
  16.             Console.ReadLine();
  17.         }
  18.     }
  19. }
  20.  

Código: C#
  1. using System;
  2.  
  3. namespace IndexadoresArray
  4. {
  5.     class Datos
  6.     {
  7.         private int[] numeros =  new int[10];
  8.  
  9.         public int this[byte indice]
  10.         {
  11.             get { return numeros[indice]; }
  12.             set { numeros[indice] = value; }
  13.         }
  14.        
  15.         public void _Datos()
  16.         {
  17.             Datos obj = new Datos();
  18.             byte _top = 2,hasElMom = 1;
  19.             int aux = 0;
  20.             Console.SetCursorPosition(02, _top);
  21.             Console.Write("Ingrese 10 entero(máximo 99999)");
  22.             _top += 2;
  23.             Console.SetCursorPosition(02, _top);
  24.             Console.Write("Natutal   Ordenados");
  25.             _top += 2;
  26.             for (byte i = 0; i < 10; i++)
  27.             {
  28.                 while (true)
  29.                 {
  30.                     Console.SetCursorPosition(02, _top);
  31.                     Console.Write("");
  32.                     if ((int.TryParse(Console.ReadLine(), out aux)) && aux < 100000)
  33.                     {
  34.                         obj[i] = aux;
  35.                         break;
  36.                     }
  37.                 }
  38.                 Array.Sort(numeros);
  39.                 byte _topOrd = 6;
  40.                 for (byte f = 0; f < hasElMom; f++)
  41.                 {
  42.                     Console.SetCursorPosition(12, _topOrd);
  43.                     Console.Write("{0}", obj[f]);
  44.                     _topOrd++;
  45.                 }
  46.                 _top++;
  47.                 hasElMom++;
  48.             }
  49.         }
  50.     }
  51. }
  52.  

Bueno espero aflojar un poco, tengo miedo de cansarlos.-
Saludos.
Daniel

PD. Por unas horas voy a estar un poco ocupado en otra cosa (a las 19.10 juega la selección - Argentina)
abraza las cosas y personas malas como si fueran tu mas preciada joya,Son tus mas grandes maestros de paciencia sabiduría y amor y cuando lo abrazas dejan de causar dolor.-

gabio2

  • Miembro MUY activo
  • ***
  • Mensajes: 402
  • Nacionalidad: mx
    • Ver Perfil
Re:Indexadores en C#
« Respuesta #1 en: Miércoles 28 de Agosto de 2013, 05:01 »
0
no sé que quisiste hacer, pero... creo que tal vez te refieres a esto:

http://msdn.microsoft.com/library/vstudio/6x16t2tx

Saludos.
@gabio87

DanielC#

  • Miembro activo
  • **
  • Mensajes: 39
  • Nacionalidad: ar
    • Ver Perfil
Re:Indexadores en C#
« Respuesta #2 en: Jueves 29 de Agosto de 2013, 00:10 »
0
Hola a todos.
Bueno al fin lo logre me faltan algunas cosas pero funciona de una manera aceptable.-

Código: C#
  1. using System;
  2.  
  3. namespace IndexadoresArray
  4. {
  5.     class ProgramaApp
  6.     {
  7.         static void Main(string[] argumentos)
  8.         {
  9.             Entorno entorno = new Entorno();
  10.             entorno._entorno();
  11.            
  12.             Datos datos = new Datos();
  13.             datos._Datos();
  14.  
  15.             Console.Write("\n\n Pulse una tecla para cerrar la aplicación...");
  16.             Console.ReadLine();
  17.         }
  18.     }
  19. }

Código: C#
  1. using System;
  2.  
  3. namespace IndexadoresArray
  4. {
  5.     class Entorno
  6.     {
  7.         public void _entorno()
  8.         {
  9.             Console.Title = " Indexadores";
  10.             Console.WindowHeight = 30;
  11.             Console.WindowWidth = 70;
  12.             Console.BackgroundColor = ConsoleColor.Blue;
  13.             Console.ForegroundColor = ConsoleColor.Yellow;
  14.             Console.Clear();
  15.         }
  16.     }
  17. }
  18.  

Código: C#
  1. using System;
  2.  
  3. namespace IndexadoresArray
  4. {
  5.     class Datos
  6.     {
  7.         private int[] numeros = new int[5];
  8.        
  9.         public int this[byte indice]
  10.         {
  11.             get { return numeros[indice];}
  12.             set { numeros[indice] = value;}
  13.         }
  14.  
  15.         public void _Datos()
  16.         {
  17.             Datos obj = new Datos();
  18.             byte _top = 2;
  19.             int aux = 0;
  20.             Console.SetCursorPosition(02, _top);
  21.             Console.Write("Ingrese 10 entero(máximo 99999)");
  22.             _top += 2;
  23.             Console.SetCursorPosition(02, _top);
  24.             Console.Write("Natutal   Ordenados");
  25.             _top += 2;
  26.             Ordenar ordenar = new Ordenar();
  27.             for (byte i = 0; i < numeros.Length; i++)
  28.             {
  29.                 while (true)
  30.                 {
  31.                     Console.SetCursorPosition(02, _top);
  32.                     Console.Write("");
  33.                     if ((int.TryParse(Console.ReadLine(), out aux)) && aux < 100000)
  34.                     {
  35.                         obj[i] = aux;
  36.                         break;
  37.                     }
  38.                 }
  39.                 _top++;
  40.                 ordenar.ordenar(obj.numeros, i);
  41.             }
  42.         }
  43.     }
  44. }

Código: C#
  1. using System;
  2.  
  3. namespace IndexadoresArray
  4. {
  5.     class Ordenar
  6.     {
  7.         public void ordenar(int[] aOrdenar,int cTraigo)
  8.         {
  9.             int temp = 0; cTraigo++;
  10.             for (int e = 0; e < cTraigo; e++)
  11.             {
  12.                 for (int i = 0; i < cTraigo - 1; i++)
  13.                 {
  14.                     if (aOrdenar[i] > aOrdenar[i + 1])
  15.                     {
  16.                         temp = aOrdenar[i];
  17.                         aOrdenar[i] = aOrdenar[i + 1];
  18.                         aOrdenar[i + 1] = temp;
  19.                     }
  20.                 }
  21.             }
  22.             byte filaCd = 6;
  23.             for (byte m = 0; m < cTraigo; m++)
  24.             {
  25.                 Console.SetCursorPosition(12, filaCd); Console.Write("                   ");
  26.                 Console.SetCursorPosition(12, filaCd); Console.Write("" + aOrdenar[m]);
  27.                 filaCd++;
  28.             }
  29.         }
  30.     }
  31. }

Saludos y hasta la proxima.-
Daniel
abraza las cosas y personas malas como si fueran tu mas preciada joya,Son tus mas grandes maestros de paciencia sabiduría y amor y cuando lo abrazas dejan de causar dolor.-