CLR: .Net / Mono / Boo / Otros CLR > C#
Indexadores en C#
(1/1)
DanielC#:
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# ---using System; namespace IndexadoresArray{ class ProgramaApp { static void Main(string[] argumentos) { Entorno _Entorno = new Entorno(); _Entorno._entorno(); Datos _datos = new Datos(); _datos._Datos(); Console.Write("\n\n Pulse una tecla para cerrar la aplicación..."); Console.ReadLine(); } }}
--- Código: C# ---using System; namespace IndexadoresArray{ class Datos { private int[] numeros = new int[10]; public int this[byte indice] { get { return numeros[indice]; } set { numeros[indice] = value; } } public void _Datos() { Datos obj = new Datos(); byte _top = 2,hasElMom = 1; int aux = 0; Console.SetCursorPosition(02, _top); Console.Write("Ingrese 10 entero(máximo 99999)"); _top += 2; Console.SetCursorPosition(02, _top); Console.Write("Natutal Ordenados"); _top += 2; for (byte i = 0; i < 10; i++) { while (true) { Console.SetCursorPosition(02, _top); Console.Write(""); if ((int.TryParse(Console.ReadLine(), out aux)) && aux < 100000) { obj[i] = aux; break; } } Array.Sort(numeros); byte _topOrd = 6; for (byte f = 0; f < hasElMom; f++) { Console.SetCursorPosition(12, _topOrd); Console.Write("{0}", obj[f]); _topOrd++; } _top++; hasElMom++; } } }}
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)
gabio2:
no sé que quisiste hacer, pero... creo que tal vez te refieres a esto:
http://msdn.microsoft.com/library/vstudio/6x16t2tx
Saludos.
DanielC#:
Hola a todos.
Bueno al fin lo logre me faltan algunas cosas pero funciona de una manera aceptable.-
--- Código: C# ---using System; namespace IndexadoresArray{ class ProgramaApp { static void Main(string[] argumentos) { Entorno entorno = new Entorno(); entorno._entorno(); Datos datos = new Datos(); datos._Datos(); Console.Write("\n\n Pulse una tecla para cerrar la aplicación..."); Console.ReadLine(); } }}
--- Código: C# ---using System; namespace IndexadoresArray{ class Entorno { public void _entorno() { Console.Title = " Indexadores"; Console.WindowHeight = 30; Console.WindowWidth = 70; Console.BackgroundColor = ConsoleColor.Blue; Console.ForegroundColor = ConsoleColor.Yellow; Console.Clear(); } }}
--- Código: C# ---using System; namespace IndexadoresArray{ class Datos { private int[] numeros = new int[5]; public int this[byte indice] { get { return numeros[indice];} set { numeros[indice] = value;} } public void _Datos() { Datos obj = new Datos(); byte _top = 2; int aux = 0; Console.SetCursorPosition(02, _top); Console.Write("Ingrese 10 entero(máximo 99999)"); _top += 2; Console.SetCursorPosition(02, _top); Console.Write("Natutal Ordenados"); _top += 2; Ordenar ordenar = new Ordenar(); for (byte i = 0; i < numeros.Length; i++) { while (true) { Console.SetCursorPosition(02, _top); Console.Write(""); if ((int.TryParse(Console.ReadLine(), out aux)) && aux < 100000) { obj[i] = aux; break; } } _top++; ordenar.ordenar(obj.numeros, i); } } }}
--- Código: C# ---using System; namespace IndexadoresArray{ class Ordenar { public void ordenar(int[] aOrdenar,int cTraigo) { int temp = 0; cTraigo++; for (int e = 0; e < cTraigo; e++) { for (int i = 0; i < cTraigo - 1; i++) { if (aOrdenar[i] > aOrdenar[i + 1]) { temp = aOrdenar[i]; aOrdenar[i] = aOrdenar[i + 1]; aOrdenar[i + 1] = temp; } } } byte filaCd = 6; for (byte m = 0; m < cTraigo; m++) { Console.SetCursorPosition(12, filaCd); Console.Write(" "); Console.SetCursorPosition(12, filaCd); Console.Write("" + aOrdenar[m]); filaCd++; } } }}
Saludos y hasta la proxima.-
Daniel
Navegación
Ir a la versión completa