C#

Extension methods

Në shqip: Metodat shtesë

ShpjegimiSQ

Metodat shtesë të lejojnë t'i „shtosh“ metoda një klase që s'është e jotja — p.sh. string-ut — pa e ndryshuar. Shkruhen si metoda static me this para parametrit të parë. Gjithë LINQ-u është ndërtuar kështu.

EnglishEN

Extension methods let you “add” methods to a class you don't own — like string — without changing it. They're written as static methods with this before the first parameter. All of LINQ is built this way.

Si ta mendosh

Si t'i vësh një mbajtëse celulari biçikletës: biçikleta mbetet e njëjtë, por tani bën diçka më shumë.

Lexoje në anglisht

Like clipping a phone holder onto a bike: the bike's the same, but now it does one more thing.

Shembull kodicsharp

static class Zgjerime {
    public static bool EshteBosh(this string s) => s.Trim().Length == 0;
}
"   ".EshteBosh();   // true

Terma të lidhur