提问人:Artemis 提问时间:12/7/2022 最后编辑:phoArtemis 更新时间:12/8/2022 访问量:90
我在引用命名空间时遇到问题
I'm having a problem when referencing a namespace
问:
我将三个脚本从同一个文件夹中分离出来,因为一个脚本干扰了另一个脚本,当引用其中一个脚本中的命名空间时,我收到“缺少使用指令/程序集引用”错误
我尝试运行该命令,但它最终没有做任何事情dotnet add reference
不知道把代码放在哪里,所以...
它不必要地复杂化,但忽略了错误与使用 错误是 Vector3 和使用 thingys
脚本 1
namespace StateCalculator
{
using System;
using System.Configuration;
using System.Runtime.InteropServices;
using System.IO;
using System.Linq;
using CustomVariablesAndFunctionsEngine.Vectors; <- Error
using CustomVariablesAndFunctionsEngine.Math; <- Error
public class Calculator
{
#region Variables
public CalculatorStateMachine StateMachine { get; private set; }
public Add Add { get; private set; }
public Subtract Subtract { get; private set; }
public Multiply Multiply { get; private set; }
public Divide Divide { get; private set; }
public Square Square { get; private set; }
public Sqrt Sqrt { get; private set; }
public Cube Cube { get; private set; }
public Cbrt Cbrt { get; private set; }
#endregion
#region Functions
static void Main(string[] args)
{
Calculator c = new Calculator();
c.Awake();
c.Round1();
}
private void Awake()
{
StateMachine = new CalculatorStateMachine();
Add = new Add(this, StateMachine);
Subtract = new Subtract(this, StateMachine);
Multiply = new Multiply(this, StateMachine);
Divide = new Divide(this, StateMachine);
Square = new Square(this, StateMachine);
Sqrt = new Sqrt(this, StateMachine);
Cube = new Cube(this, StateMachine);
Cbrt = new Cbrt(this, StateMachine);
}
private void Round1()
{
string YesOrNo;
int operation;
Console.WriteLine("This is a simple calculator");
Console.WriteLine("Would you like to Continue Yes/No");
YesOrNo = Console.ReadLine().ToLower();
if(YesOrNo == "yes")
{
Console.WriteLine("What operation do you want to use");
Console.WriteLine("1 : Add");
Console.WriteLine("2 : Subtract");
Console.WriteLine("3 : Multiply");
Console.WriteLine("4 : Divide");
Console.WriteLine("5 : Square");
Console.WriteLine("6 : Sqrt");
Console.WriteLine("7 : Cube");
Console.WriteLine("8 : Cbrt");
operation = Convert.ToInt32(Console.ReadLine());
Which(operation);
}
else
{
Console.WriteLine("Ok, sorry to see you go :(");
}
}
private void Which(int operation)
{
if(operation == 1)
{
StateMachine.ChangeOperation(Add);
}
else if (operation == 2)
{
StateMachine.ChangeOperation(Subtract);
}
else if (operation == 3)
{
StateMachine.ChangeOperation(Multiply);
}
else if (operation == 4)
{
StateMachine.ChangeOperation(Divide);
}
else if(operation == 5)
{
StateMachine.ChangeOperation(Square);
}
else if(operation == 6)
{
StateMachine.ChangeOperation(Sqrt);
}
else if(operation == 7)
{
StateMachine.ChangeOperation(Cube);
}
else if(operation == 8)
{
StateMachine.ChangeOperation(Cbrt);
}
else
{
Console.WriteLine("Sorry I cant do that");
Which(operation);
}
}
#endregion
}
public class CalculatorStateMachine
{
#region Variables
public Operation CurrentOperation { get; private set; }
#endregion
#region Functions
public void Initialize(Operation startingOperation)
{
CurrentOperation = startingOperation;
CurrentOperation.Enter();
}
public void ChangeOperation(Operation newOperation)
{
CurrentOperation = newOperation;
CurrentOperation.Enter();
}
#endregion
}
public class Operation
{
#region Variables
public Calculator Calculator { get; protected set; }
public CalculatorStateMachine StateMachine { get; protected set; }
protected Vector3 Numbers;
#endregion
#region Functions
public Operation(Calculator calculator, CalculatorStateMachine stateMachine)
{
this.Calculator = calculator;
this.StateMachine = stateMachine;
}
public virtual void Enter()
{
Numbers = new Vector3(0f, 0f, 0f);
SetVariables();
Calculate(this.Numbers);
}
public virtual void SetVariables()
{
}
public virtual void Calculate(Vector3 Numbers)
{
}
#endregion
}
public class Add : Operation
{
public Add(Calculator calculator, CalculatorStateMachine stateMachine) : base(calculator, stateMachine)
{
}
public override void Enter()
{
base.Enter();
}
public override void Calculate(Vector3 Numbers)
{
base.Calculate(Numbers);
Numbers.z = Numbers.x + Numbers.y;
Console.WriteLine("Your answer is " + Convert.ToString(Numbers.z));
}
public override void SetVariables()
{
base.SetVariables();
Console.WriteLine("First Number");
Numbers.x = Convert.ToSingle(Console.ReadLine());
Console.WriteLine("Second Number");
Numbers.y = Convert.ToSingle(Console.ReadLine());
}
}
public class Subtract : Operation
{
public Subtract(Calculator calculator, CalculatorStateMachine stateMachine) : base(calculator, stateMachine)
{
}
public override void Enter()
{
base.Enter();
}
public override void Calculate(Vector3 Numbers)
{
base.Calculate(Numbers);
Numbers.z = Numbers.x - Numbers.y;
Console.WriteLine("Your answer is " + Convert.ToString(Numbers.z));
}
public override void SetVariables()
{
base.SetVariables();
Console.WriteLine("First Number");
Numbers.x = Convert.ToSingle(Console.ReadLine());
Console.WriteLine("Second Number");
Numbers.y = Convert.ToSingle(Console.ReadLine());
}
}
public class Multiply : Operation
{
public Multiply(Calculator calculator, CalculatorStateMachine stateMachine) : base(calculator, stateMachine)
{
}
public override void Enter()
{
base.Enter();
}
public override void Calculate(Vector3 Numbers)
{
base.Calculate(Numbers);
Numbers.z = Numbers.x * Numbers.y;
Console.WriteLine("Your answer is " + Convert.ToString(Numbers.z));
}
public override void SetVariables()
{
base.SetVariables();
Console.WriteLine("First Number");
Numbers.x = Convert.ToSingle(Console.ReadLine());
Console.WriteLine("Second Number");
Numbers.y = Convert.ToSingle(Console.ReadLine());
}
}
public class Divide : Operation
{
public Divide(Calculator calculator, CalculatorStateMachine stateMachine) : base(calculator, stateMachine)
{
}
public override void Enter()
{
base.Enter();
}
public override void Calculate(Vector3 Numbers)
{
base.Calculate(Numbers);
Numbers.z = Numbers.x / Numbers.y;
Console.WriteLine("Your answer is " + Convert.ToString(Numbers.z));
}
public override void SetVariables()
{
base.SetVariables();
Console.WriteLine("First Number");
Numbers.x = Convert.ToSingle(Console.ReadLine());
Console.WriteLine("Second Number");
Numbers.y = Convert.ToSingle(Console.ReadLine());
}
}
public class Square : Operation
{
public Square(Calculator calculator, CalculatorStateMachine stateMachine) : base(calculator, stateMachine)
{
}
public override void Enter()
{
base.Enter();
}
public override void Calculate(Vector3 Numbers)
{
base.Calculate(Numbers);
Numbers.z = MathF.Pow(Numbers.x, 2f);
Console.WriteLine("Your answer is " + Convert.ToString(Numbers.z));
}
public override void SetVariables()
{
base.SetVariables();
Console.WriteLine("Number");
Numbers.x = Convert.ToSingle(Console.ReadLine());
}
}
public class Sqrt : Operation
{
public Sqrt(Calculator calculator, CalculatorStateMachine stateMachine) : base(calculator, stateMachine)
{
}
public override void Enter()
{
base.Enter();
}
public override void Calculate(Vector3 Numbers)
{
base.Calculate(Numbers);
Numbers.z = MathF.Sqrt(Numbers.x);
Console.WriteLine("Your answer is " + Convert.ToString(Numbers.z));
}
public override void SetVariables()
{
base.SetVariables();
Console.WriteLine("Number");
Numbers.x = Convert.ToSingle(Console.ReadLine());
}
}
public class Cube : Operation
{
public Cube(Calculator calculator, CalculatorStateMachine stateMachine) : base(calculator, stateMachine)
{
}
public override void Enter()
{
base.Enter();
}
public override void Calculate(Vector3 Numbers)
{
base.Calculate(Numbers);
Numbers.z = MathF.Pow(Numbers.x, 3f);
Console.WriteLine("Your answer is " + Convert.ToString(Numbers.z));
}
public override void SetVariables()
{
base.SetVariables();
Console.WriteLine("Number");
Numbers.x = Convert.ToSingle(Console.ReadLine());
}
}
public class Cbrt : Operation
{
public Cbrt(Calculator calculator, CalculatorStateMachine stateMachine) : base(calculator, stateMachine)
{
}
public override void Enter()
{
base.Enter();
}
public override void Calculate(Vector3 Numbers)
{
base.Calculate(Numbers);
Numbers.z = MathF.Cbrt(Numbers.x);
Console.WriteLine("Your answer is " + Convert.ToString(Numbers.z));
}
public override void SetVariables()
{
base.SetVariables();
Console.WriteLine("Number");
Numbers.x = Convert.ToSingle(Console.ReadLine());
}
}
}
答:
1赞
Artemis
12/8/2022
#1
我通过将代码传输到 Visual Studio 控制台应用程序,然后在解决方案中添加 using 指令作为引用来修复它
上一个:为什么我会遇到这个问题?[关闭]
下一个:从 C 中的聚合函数中获取计数#
评论