Ver Mensaje Individual
  #3  
Antiguo 07-12-2007
Avatar de jhonny
jhonny jhonny is offline
Jhonny Suárez
 
Registrado: may 2003
Ubicación: Colombia
Posts: 7.058
Reputación: 29
jhonny Va camino a la famajhonny Va camino a la fama
Acabo de probar el siguiente codigo que encontre en http://www.elguille.info/NET/cursoCS.../Entrega12.htm y verifique que sigue funcionando dicho servicio:

Código:
using System;

using System.Collections;

 

namespace IndizadorLibros

{

    class Libro

    {

        private ArrayList capitulos=new ArrayList();

 

        public object this[int indice]

        {

            get

            {

                if (indice >= capitulos.Count || indice < 0)

                    return null;

                else

                    return capitulos[indice];

            }

            set

            {

                if (indice >= 0 && indice < capitulos.Count)

                    capitulos[indice]=value;

                else if (indice == capitulos.Count)

                    capitulos.Add(value);

                else

                    throw new Exception("No se puede asignar a este elemento");

            }

        }    

    

        public int NumCapitulos

        {

            get

            {

                return capitulos.Count;

            }

        }

    }

 

    class IndizadorLibrosApp

    {

        static void Main()

        {

            Libro miLibro=new Libro();

 

            miLibro[0]="La psicología de la musaraña";

            miLibro[1]="¿Puede una hormiga montar en bicicleta?";

            miLibro[1]="Un pedrusco en manos de Miró es un Miró";

 

            for (int i=0;i<miLibro.NumCapitulos;i++)

                Console.WriteLine("Capitulo {0}: {1}",i+1,miLibro[i]);

 

            string a=Console.ReadLine();

        }

    }

}

Me lo ha convertido en esto:

Código Delphi [-]
//------------------------------------------------------------------------------
// 
//     This code was generated by a tool.
//     Runtime Version: 1.1.4322.2407
//
//     Changes to this file may cause incorrect behavior and will be lost if 
//     the code is regenerated.
// 
//------------------------------------------------------------------------------

unit IndizadorLibros;

interface

type
  Libro = class
  strict private
    capitulos: ArrayList;
  public
    function get_this(indice: Integer): System.Object;
    function get_NumCapitulos: Integer;
    procedure set_this(indice: Integer; Value: System.Object);
    property this[indice: Integer]: System.Object read get_this write set_this;
    property NumCapitulos: Integer read get_NumCapitulos;
  end;
  
  
  IndizadorLibrosApp = class
  strict private
    class procedure Main;static; 
  end;
  
implementation

{$AUTOBOX ON}
{$HINTS OFF}
{$WARNINGS OFF}

function Libro.get_this(indice: Integer): System.Object;
begin
  if ((indice >= Self.capitulos.Count) or (indice < 0)) then
    begin
      Result := nil;
      Exit;
    end
  else
    begin
      Result := Self.capitulos[indice];
      Exit;
    end;
end;

function Libro.get_NumCapitulos: Integer;
begin
  Result := Self.capitulos.Count;
end;

procedure Libro.set_this(indice: Integer; Value: System.Object);
begin
  if ((indice >= 0) and (indice < Self.capitulos.Count)) then
    Self.capitulos[indice] := value
  else
    if (indice = Self.capitulos.Count) then
      Self.capitulos.Add(value)
    else
      raise Exception.Create('No se puede asignar a este elemento');
end;

class procedure IndizadorLibrosApp.Main;
var
  a: string;
  i: Integer;
  miLibro: Libro;
begin
  miLibro := Libro.Create;
  miLibro[0] := 'La psicolog?a de la musara?a';
  miLibro[1] := '?Puede una hormiga montar en bicicleta?';
  miLibro[1] := 'Un pedrusco en manos de Mir? es un Mir?';
  i := 0;
  while (i < miLibro.NumCapitulos) do
  begin
    Console.WriteLine('Capitulo {0}: {1}', (i + 1), miLibro[i]);
    /*PostInc*/;
  end;
  a := Console.ReadLine;
end;

end.
__________________
Lecciones de mi Madre. Tema: modificación del comportamiento, "Pará de actuar como tu padre!"

http://www.purodelphi.com/
http://www.nosolodelphi.com/

Última edición por jhonny fecha: 07-12-2007 a las 22:17:42.
Responder Con Cita