IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesC#  Print This     

Overloading (C# and Delphi Cross Reference Guide)

By Mike Prestwood

C# versus Delphi: A side by side comparison between C# and Delphi.

 
Language Details
 

Language Details is kind of a catch all for stuff that didn't make it into language basics nor any other category.

Overloading

[Other Languages] 

Types of overloading include method overloading and operator overloading.

Method Overloading is where different functions with the same name are invoked based on the data types of the parameters passed or the number of parameters. Method overloading is a type of polymorphism and is also known as Parametric Polymorphism.

Operater Overloading allows an operator to behave differently based on the types of values used. For example, in some languages the + operator is used both to add numbers and to concatenate strings. Custom operator overloading is sometimes referred to as ad-hoc polymorphism.

C#:   implicit

C# supports both method and operator overloading.

For methods, C# supports implicit overloading (no need for an overload keyword).

Delphi:   overload

Delphi supports both method and operator overloading.

For method overloading, you use the overload keyword (all versions of the routine must include the overload keyword). The compiler chooses the correct method first based on the number of parameters, then on the type so you can have two overloaded methods with the same number of parameters so long as at least one parameter is different.

Another form of method overloading is with the use of default parameters, a shortcut syntax, where you specify a default parameter value.

Delphi also supports operator overloading with some operators.

Syntax Example:
function Add(a, b: integer): Integer;  overload;
begin
Result := a+b;
end;
  
function Add(const msg: String; a, b: integer): String; overload;
begin
  Result := msg + IntToStr(a+b);
end;












Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]