Suppose I have code segment
namespace Test
{
public delegate void StaticticsDelegate(object sender,EventArgs e);
class DynamicDelegates
{
static void Main()
{
StaticticsDelegate del = BowlerStatistics;
BallThrownEventArgs be = new BallThrownEventArgs(90, 145);
del(DynamicDelegates.Main,be);
del = BatsmanStatistics;
RunsScoredEventArgs re = new RunsScoredEventArgs("Skeet", 55);
del(DynamicDelegates.Main, re);
Console.ReadLine();
}
static void BowlerStatistics(object sender, BallThrownEventArgs e)
{
Console.WriteLine
("{0} sender is ; Bowler Statistics :speed {1} angle {2}",
sender, e.Speed, e.Angle);
}
static void BatsmanStatistics(object sender, RunsScoredEventArgs e)
{
Console.WriteLine
("{0} sender is ; Batsman Statistics :name {1} runs {2}",
sender, e.PlayerName, e.Runs);
}
}
class BallThrownEventArgs:EventArgs
{
int angle;
int speed;
public BallThrownEventArgs(int angle, int speed)
{
this.angle = angle;
this.speed = speed;
}
public int Angle
{
get { return angle; }
}
public int Speed
{
get { return speed; }
}
}
class RunsScoredEventArgs : EventArgs
{
string playerName;
int runs;
public RunsScoredEventArgs(string playerName, int runs)
{
this.playerName = playerName;
this.runs = runs;
}
public string PlayerName
{
get { return playerName; }
}
public int Runs
{
get { return runs; }
}
}
}
1) Since "BallThrownEventArgs" and "RunsScoredEventsArgs" are derived from "EventArgs", why did the error "No overloads for Matches..." generate when i "Main()" is executed.
2) What do you mean by "ContraVariance" and "Covariance" (Please give me an example to understand) ?
3) The term "Contravariance" and "Covariance" are related to delegates only ?