Operator overloading (C#)
Në shqip: Mbingarkimi i operatorëve në C#
ShpjegimiSQ
Me public static Vektor operator +(Vektor a, Vektor b) i mëson C#-it çfarë do të thotë + për klasën tënde — që të shkruash a + b si me numrat.
EnglishEN
With public static Vector operator +(Vector a, Vector b) you teach C# what + means for your class — so you can write a + b just like with numbers.
Si ta mendosh
Si t'i mësosh kalkulatorit të mbledhë edhe fruta.
Lexoje në anglisht
Like teaching the calculator to add fruit as well.
Shembull kodicsharp
public record Vektor(double X, double Y) {
public static Vektor operator +(Vektor a, Vektor b) => new(a.X + b.X, a.Y + b.Y);
}