type
KG = public record
private
fValue: Double;
public
constructor(aValue: Double);
begin
fValue := aValue;
{$IFDEF DEBUG}
if aValue < 0 then raise new ArgumentException('Invalid value!');
{$ENDIF}
end;
operator explicit(aValue: Double): KG; begin exit new KG(aValue) ;end;
operator explicit(aValue: KG): Double; begin exit aValue.Value; ;end;
property Value: Double read fValue;
method ToString: String; override;
begin
exit fValue.ToString()+' kg';
end;
end;
namespace ConsoleApplication833;
type
KG = public record mapped to Double
public
constructor(aValue: Double); inline;
begin
self := aValue;
{$IFDEF DEBUG}
if aValue < 0 then raise new ArgumentException('Invalid value!');
{$ENDIF}
end;
property Value: Double read mapped;
class operator Implicit(aVal: Double): KG; inline;
begin
exit new KG(aVal);
end;
method ToString: String; override;
begin
exit mapped.ToString()+' kg';
end;
end;
Program = class
public
class method Main(args: array of String): Int32;
begin
var x: KG := KG(15.0);
x := Double(x) + 15;
// add your own code here
writeLn('The magic happens here.');
end;
end;
end.
becomes:
// ConsoleApplication833.Program
using System;
public static int Main(string[] args)
{
double num = default(double);
num = 15.0;
if (15.0 < 0.0)
{
throw new ArgumentException("Invalid value!");
}
double x2 = num;
x2 += 15.0;
Console.Out.WriteLine("The magic happens here.");
int Result = default(int);
return Result;
}