Cita:
Empezado por rretamar
(igual sigo prefiriendo la sintaxis de Object Pascal, la encuentro mucho más amigable "programación para seres humanos" ).
|
Yo tambien la prefiero pero estas dos cosas de C# sería bueno tenerlas en Delphi para mi gusto.
1. el asignar propiedades.
Código:
En Delphi
type MyClass = class(tObject)
private
fMyProp : integer;
function GetMyProp: integer;
procedure SetMyProp(const Value: integer);
public
property MyProp : integer read GetMyProp write SetMyProp;
end;
function MyClass.GetMyProp: integer;
begin
result:= max(fMyProp,0);
end;
procedure MyClass.SetMyProp(const Value: integer);
begin
if Value >= 0 then
fMyProp:= Value;
end;
En C#
Código:
public class MyClass
{
private int myProp = 0;
public int MyProp
{
get { return Math.Max(myProp, 0); }
set { if (value > 0)
myProp = value; }
}
}
2. try catch con finally
en C#
Código:
try
{
throw New MyException("Error occurred in C#");
}
catch(MyException)
{
HandleMyException();
}
finally
{
CleanUp();
}
Esto en delphi requiere de abrir dos try, el primero con el finally y el segundo con el catch