我是初学者,我正在使用记事本制作一个简单的计算器。它有3个文件。 1.第一个文件有一些函数,如加法,减法等编译为dll文件。
现在,当我尝试在第二个文件中添加第一个文件的引用时,我收到错误。
错误cs0143:“计算器”类型(第一个文件)没有 构造函数定义。
如何删除此错误?
Calculator.cs
using System;
public class Calculator
{
public double Addition(double x, double y)
{
return x+y;
}
public double Subtraction(double x, double y)
{
return x-y;
}
public double Multiplication(double x, double y)
{
return x*y;
}
public double Division(double x, double y)
{
return x/y;
}
public double Mod(double x, double y)
{
return x%y;
}
}
CalculatorUI.cs
using System;
public class CalculatorUI
{
Calculator a=new Calculator();
public void Menu()
{
Console.WriteLine("1: Addition");
Console.WriteLine("2: Subtraction");
Console.WriteLine("3: Multiplication");
Console.WriteLine("4: Division");
Console.WriteLine("5: Mod");
Console.WriteLine("6: Square Root");
Console.WriteLine("7: Exit");
Console.WriteLine("Press any key to continue . . . ");
}
private void Addition(string[] args)
{
Console.WriteLine("Enter First Value : ");
double num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Second Value : ");
double num2 = Convert.ToInt32(Console.ReadLine());
double ans=a.Addition(num1,num2);
Console.WriteLine("The Answer is ---> "+ans);
}
private void Subtraction(string[] args)
{
Console.WriteLine("Enter First Value : ");
double num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Second Value : ");
double num2 = Convert.ToInt32(Console.ReadLine());
double ans=a.Subtraction(num1,num2);
Console.WriteLine("The Answer is ---> "+ans);
}
private void Multiplication(string[] args)
{
Console.WriteLine("Enter First Value : ");
double num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Second Value : ");
double num2= Convert.ToInt32(Console.ReadLine());
double ans=a.Multiplication(num1,num2);
Console.WriteLine("The Answer is ---> "+ans);
}
private void Division(string[] args)
{
Console.WriteLine("Enter First Value : ");
double num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Second Value : ");
double num2 = Convert.ToInt32(Console.ReadLine());
double ans=a.Division(num1,num2);
Console.WriteLine("The Answer is ---> "+ans);
}
private void Mod(string[] args)
{
Console.WriteLine("Enter First Value : ");
double num1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Second Value : ");
double num2 = Convert.ToInt32(Console.ReadLine());
double ans=a.Mod(num1,num2);
Console.WriteLine("The Answer is ---> "+ans);
}
}