在 vscode 中使用 C# 输入控制台应用程序
我试图通过制作一个控制台游戏来测试我的傻瓜大脑,因为我认为我很擅长编程,并且陷入了库存(即在库存中的每个项目上进行 foreach
你按“我”)但意识到我太笨了。这就是我写的:
string i;
var input = Console.ReadKey();
if (input = 'I') {
foreach (KeyValuePair<string, string> item in Inventory)
{
i += $"{item.Key}: {item.Value}";
}
}
else {
Console.WriteLine("(Press 'I' to open your inventory.)");
}
我知道,这可能会杀死一个程序员(我很无趣)。这是错误消息:
C:\Documents\new pogram\internet be broke 2 electric boogaloo.cs(19,13): error CS0103: The name 'I' does not exist in the current context
C:\Documents\new pogram\internet be broke 2 electric boogaloo.cs(22,9): error CS0165: Use of unassigned local variable 'i' [C:\Users\lewis_pulfff2\OneDrive\Documents\new pogram\new pogram.csproj]
The build failed. Fix the build errors and run again.
我尝试寻找其他软件,但示例不起作用。
arigatogozaimasu(和 gomennasorry)提前:D。
i tried to test my dum-dum brain by making a console game because i thought that i was gud at programming, and got stuck on the inventory (i.e. going through a foreach
for each item in the inventory when you press 'I') but realised i'm too dum-dum for that. here's what i wrote:
string i;
var input = Console.ReadKey();
if (input = 'I') {
foreach (KeyValuePair<string, string> item in Inventory)
{
i += quot;{item.Key}: {item.Value}";
}
}
else {
Console.WriteLine("(Press 'I' to open your inventory.)");
}
i know, this could kill a PROgrammer (i'm so unfunny). here were the error messages:
C:\Documents\new pogram\internet be broke 2 electric boogaloo.cs(19,13): error CS0103: The name 'I' does not exist in the current context
C:\Documents\new pogram\internet be broke 2 electric boogaloo.cs(22,9): error CS0165: Use of unassigned local variable 'i' [C:\Users\lewis_pulfff2\OneDrive\Documents\new pogram\new pogram.csproj]
The build failed. Fix the build errors and run again.
i tried looking else ware, but the samples didn't work.
arigatogozaimasu (and gomennasorry) in advance :D.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您曾经
在发布代码之前更改过它 - 这是第一个错误的原因。
您还意味着
EDIT
加 ReadKey 返回的内容多于按键 - 请参阅 https://learn.microsoft.com/en-us/dotnet/api/system.console.readkey?view=net-6.0
所以你需要
第二个错误来自
你需要的
I will assume that you used to have
but changed that before posting the code - this was the cause of the first error.
also you mean
EDIT
plus ReadKey returns more than the key press - see https://learn.microsoft.com/en-us/dotnet/api/system.console.readkey?view=net-6.0
so you need
THe second error comes from here
you need