当前上下文中不存在名称“xx" [英] The name 'xx' does not exist in the current context
问题描述
不太确定我做错了什么.我得到的错误是:
Not quite sure what I'm doing wrong. The errors I'm getting are:
名称_questions"在当前上下文中不存在 - FormChoose.cs
The name '_questions' does not exist in the current context - FormChoose.cs
代码:
FormChoose.cs
FormChoose.cs
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using System.Xml.Serialization;
namespace WindowsFormsApplication1
{
public partial class FormChoose : Form
{
public FormChoose()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
_questions = GetQuestions("1");
}
}
}
Form1.cs
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using System.Xml.Serialization;
任何有关如何实现这一目标的输入或答案将不胜感激.任何可以帮助处理 ltn 帖子的人都可能获得奖励/激励,这样我才能让它发挥作用.
Any input or answers on how to achieve this will be greatly appreciated. Possible reward/incentive for anyone that can help out with ltn's post so I can get it working.
谢谢.
推荐答案
您正试图从未声明的位置访问成员和方法.您尝试访问的方法和成员(_questions
和 GetQuestions()
)是 Form1
的一部分,并且您正在尝试在 FormChoose
中访问它们.唯一的方法是在FormChoose
中引用一个Form1
对象.而且我真的没有看到您在 Form1
中声明 path
应该是什么.
You're trying to access members and methods from a location where they aren't declared. The method and member you're trying to access (_questions
and GetQuestions()
), are part of Form1
, and you're trying to access them in FormChoose
. The only way to do that, is to have a reference to a Form1
object in FormChoose
. And I'm not really seeing anywhere where you are declaring what path
is supposed to be in Form1
.
这篇关于当前上下文中不存在名称“xx"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!