在Visual Studio/Xamarin/C#中未识别字典
我在这里迷路了,由于某些原因,我从第10行遇到了多个错误。我正在使用Xamarin构建一个应用程序,并且我正在尝试创建一个字典,由于某种原因,我会得到以下错误
Error IDE1007 The name 'exerciseTypes.Add' does not exist in the current context.
Error IDE1007 The name 'exerciseTypes' does not exist in the current context.
Error IDE1007 The name 'Add' does not exist in the current context.
using System;
using System.Collections.Generic;
using System.Text;
namespace Trainer_App
{
internal class Exercise
{
public static Dictionary<string, bool> exerciseTypes = new Dictionary<string, bool> ();
exerciseTypes.Add("Warmup",false);
private string name;
private int min_num_balls;
private int[] num_participants;
private string court_type;
private string[] accessories;
private static int id = 0;
public Exercise()
{
}
}
}
编辑:我希望字典是班级的一部分,而不是对象
I am lost here, for some reason I am getting multiple errors from line 10. I am building an app using Xamarin and I am trying to create a dictionary and for some reason, I get the following errors
Error IDE1007 The name 'exerciseTypes.Add' does not exist in the current context.
Error IDE1007 The name 'exerciseTypes' does not exist in the current context.
Error IDE1007 The name 'Add' does not exist in the current context.
using System;
using System.Collections.Generic;
using System.Text;
namespace Trainer_App
{
internal class Exercise
{
public static Dictionary<string, bool> exerciseTypes = new Dictionary<string, bool> ();
exerciseTypes.Add("Warmup",false);
private string name;
private int min_num_balls;
private int[] num_participants;
private string court_type;
private string[] accessories;
private static int id = 0;
public Exercise()
{
}
}
}
Edit: I want the dictionary to be a part of the class and not the Objects
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能将方法调用直接放在类声明下。但是,您可以将其移入构造函数中:
You can't place a method call directly under a class declaration. You could move it inside the constructor though: