Answer the question
In order to leave comments, you need to log in
Is overloading methods nothing more than syntactic sugar?
Is method overloading anything more than syntactic sugar?
There is a class in which there are several methods called Calculate() , which have arguments (string and int).
The method call will be: or
But I can call methods like: calculateString() and calculateInt() and they will not differ from Calculate() , so we can conclude that method overloading is syntactic sugar and nothing more. Class.Calculate(string text1, string text2)
Class.Calculate(int number1, int number2).
Answer the question
In order to leave comments, you need to log in
this is definitely not sugar , but pure OOP polyformism
,
your question is rather in the plane , is it worth using polyformism?
you can google a sea of information , for example, immediately in Russian https://habr.com/ru/post/37576/
static void print(this string s, string pfx = "", string sfx = "") => Console.WriteLine(pfx + s + sfx);
static void print(this IEnumerable<string> sa, string pfx = "", string sfx = "") => sa.ToList().ForEach(s => s.print(pfx, sfx));
static void print(this string s) => Console.WriteLine(s);
static void print(this IEnumerable<string> sa) => sa.ToList().ForEach(s => s.print());
using System;
using System.Diagnostics;
using System.Linq;
namespace ff.links
{
static partial class Program
{
static void Main(string[] args)
{
var sw = new Stopwatch();
sw.Start();
"let's begin...".print();
var finds = fromTypical().scan();
"find targets is ".print(pfx, finds.Count().ToString());
//finds.print();
var bro = finds.Where(b => b.Contains(ffBinary));
"find browsers is ".print(pfx, bro.Count().ToString());
bro.print(pfx);
var cfg = finds.Where(b => b.Contains(fflConfig));
"find configs is ".print(pfx, cfg.Count().ToString());
cfg.print(pfx);
var profiles = finds.Where(b => b.Contains(ffProfileSign));
"find profiles is ".print(pfx, profiles.Count().ToString());
//profiles.print();
profiles.buildLinks(bro.First());
//profiles.prefsApplay();
//links2start();
sw.Stop();
var ts = sw.Elapsed;
$"RunTime {ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds:000}".print();
//#if DEBUG
// "press any key to continue...".print();
// Console.ReadKey();
//#endif
}
const string pfx = " ::> ";
}
}
Method overloading is a term you made up.
And what you described is an overload.
And no, it's not exactly syntactic sugar. But still part of the architecture and sometimes encapsulation of complex methods (when the number of arguments changes).
In addition, this also applies to the syntax so-so - these will be different methods from all points of view.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question