Maha

Maha

  • NA
  • 600
  • 70.9k

Extension Method

Dec 13 2014 3:43 PM
https://www.youtube.com/watch?v=D3OCSkXLFuk

This program is given in the above website.

Normally caller method and called method should have same number of parameters. But here caller method has one parameter and called method has two parameters. Please explain the reason. Problem is highlighted.

using System;

namespace Extension_Methods___YouTube
{
class Program
{
static void Main(string[] args)
{
var p = new Person { Name = "John", Age = 33 };
var p2 = new Person { Name = "Sally", Age = 35 };
p.SayHello(p2);

Console.ReadKey();
}
}

public static class Extensions
{
public static void SayHello(this Person person, Person person2)
{
Console.WriteLine("{0} says hello to {1}", person.Name, person2.Name);
}
}
}
//John says hello to Sally


Answers (2)