-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
41 lines (30 loc) · 1.6 KB
/
Program.cs
File metadata and controls
41 lines (30 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Text;
using System.Reflection;
class Program
{
static void Main()
{
Console.OutputEncoding = Encoding.Unicode;
Console.InputEncoding = Encoding.Unicode;
/*
* Завдання 3
Створіть програму, в якій надайте користувачеві доступ до збірки із завдання 2.
Реалізуйте використання методу конвертації значення температури зі шкали Цельсія в шкалу Фаренгейта. Виконуючи завдання використовуйте лише рефлексію.
*/
Assembly assembly = Assembly.LoadFrom(@"C:\Users\User\OneDrive\Рабочий стол\C#\C# Pro UA\TemperatureLibrary\bin\Debug\net8.0\TemperatureLibrary.dll");
Type type = assembly.GetType("TemperatureLibrary.TemperatureConverter");
object instanceTemperatureConverter = Activator.CreateInstance(type);
MethodInfo method = type.GetMethod("CelsiusToFahrenheit");
Console.Write("Введіть температуру в градусах Цельсія: ");
string input = Console.ReadLine();
if (double.TryParse(input, out double celsius))
{
object result = method.Invoke(instanceTemperatureConverter, new object[] { celsius });
Console.WriteLine($"Результат: {celsius}°C = {result}°F");
}
else
{
Console.WriteLine("Некоректне введення! Введіть число.");
}
}
}