static void Main(string[] args) { TemperatureConverterImp obj = new TemperatureConverterImp(); delegateConvertTemperature delConvertToFahrenheit = new delegateConvertTemperature (obj.ConvertToFahrenheit); delegateConvertTemperature delConvertToCelsius = new delegateConvertTemperature (obj.ConvertToCelsius); double celsius = 0.0; double fahrenheit = delConvertToFahrenheit(celsius); string msg1 = string.Format("Celsius = {0}, Fahrenheit = {1}", celsius, fahrenheit); Console.WriteLine(msg1); fahrenheit = 212.0; celsius = delConvertToCelsius(fahrenheit); string msg2 = string.Format("Celsius = {0}, Fahrenheit = {1}", celsius, fahrenheit); Console.WriteLine(msg2); Console.WriteLine(delConvertToCelsius.Target); Console.ReadKey(); }
static void Main(string[] args) { TemperatureConverterImp tm = new TemperatureConverterImp(); delegateConvertTemperature delF = new delegateConvertTemperature(tm.C_F); delegateConvertTemperature delC = new delegateConvertTemperature(tm.F_C); delegateConvertTemperature[] Maindel = { delF, delC }; //Через массив Console.WriteLine("100F = {0}C", Maindel[1](100)); Console.WriteLine("100C = {0}F", Maindel[0](100)); Console.WriteLine("100F = {0}C", delC(100)); Console.WriteLine("100C = {0}F", delF(100)); Console.ReadLine(); //создаем оъект.когда вызываем метод из класса вызываем через инвоук }