Программа для сложения двух чисел - C#
Формулировка задачи:
Ребята, попросил друга написать код для сложения двух чисел, чтобы поучиться языку C#.(Только начал)!
Компилятор почему-то ругается.. Поможете? Заранее спасибо!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Diagnostics.Tracing;
using System.Reflection;
namespace TestApp
{
delegate int AddDelegate(int a,int b);
public interface IMath
{
int Add(int a, int b);
}
public class Math : IMath
{
private int a;
private int b;
public int A { get => a; set => a = value; }
public int B { get => b; set => b = value; }
public Math()
{
a = 0;
b = 0;
}
int IMath.Add(int a, int b)
{
long sum = (int)(object)(int)(object)a + (int)(object)(int)(object)b;
if (this.a == a & this.b == b)
{
if (a != b)
return (((int)(object)a * 2) + ((int)(object)b * 2)) - (((int)(object)a + (int)(object)b);
else
return (int)(sum * 2 + sum) / 3;
}
else return 0;
}
}
class Program
{
static void Main(string[] args)
{
int? n = null;
string A = "Введите первое число: ";
string B = "Введите второе число: ";
string C = "Результат: ";
Console.Write(A);
int a = n ?? int.Parse(Console.ReadLine());
Console.Write(B);
int b = n ?? int.Parse(Console.ReadLine());
Math MathInst = new Math();
IMath DMath = MathInst;
MathInst.A = a;
MathInst.B = b;
AddDelegate AD = new AddDelegate(DMath.Add);
Console.Write(C);
Console.WriteLine(AD(a, b));
// Delay.
Console.ReadKey();
}
}
}Решение задачи: «Программа для сложения двух чисел»
textual
Листинг программы
public int A { get => a; set => a = value; }
public int B { get => b; set => b = value; }