Witam.
Mam taki kod:
Program.cs
class Program
{
static void Main(string[] args)
{
var person = new Person { Name = "Lucas" };
person.SaySomething();
Console.ReadKey();
}
}
public static class Extension
{
public static void SaySomething(this Person person)
{
Console.WriteLine("My name is " + person.Name);
}
}
Person.cs
public class Person
{
public string Name;
}
Jakim cudem to działa poprawnie? Metoda SaySomething jest statyczna, czyli jak wiadomo nie może być wywoływana na rzecz konkretnego obiektu. W powyższym przykładzie jest i wyświetla poprawnie. Czy to ma związek z tym, że w parametrze jest podane this Person person? Prosiłbym o wytłumaczenie.