using System;
namespace ConsoleApplication
{
class Program
{
public delegate void mydel(int z);
static void Main(string[] args)
{
Program p = new Program();
Random r = new Random();
int k = r.Next(99);
mydel f;
if (k > 50)
{
f = new mydel(p.high);
}
if (k < 50)
{
f = new mydel(p.low);
}
//f(k) is underlined and Use of unassigned local variable 'f'
f(k);
}
//methods
public void high(int m)
{
Console.WriteLine("{0}>50", m);
}
public void low(int n)
{
Console.WriteLine("{0}<50", n);
}
}
}
I expected f(k) to work because I gave parameter to delegate. Why am I getting this error? (Use of unassigned local variable 'f' on f(k) portion)