我在“Main”类中声明了一个名为“context2”的变量。但我不能在函数“Main_Load”中使用变量。我究竟做错了什么 ?
using System;
using System.Windows.Forms;
using Soapi;
using Soapi.Domain;
namespace SO_Console_Client
{
public partial class Main : Form
{
const string apiKey = "*************";
var context2 = new ApiContext(apiKey).Initialize(false);
public Main(String GravatarURL, User user)
{
InitializeComponent();
pictureBox1.Load(GravatarURL); //Loads the Gravatar image from the url
//set the reputation details
lblRep.Text = String.Format("Reputation: {0}", user.Reputation);
//Sets the badge details
lblBadge.Text = String.Format("Badges: gold={0} silver={1} bronze={2}", user.BadgeCounts.Gold, user.BadgeCounts.Silver, user.BadgeCounts.Bronze);
groupBox1.Text = user.DisplayName.ToString();
}
private void Main_Load(object sender, EventArgs e)
{
Soapi.Queries.QuestionsUnansweredQuery query = context2.Official.StackOverflow.Questions.Unanswered;
foreach (Question q in query)
{
try
{
Console.WriteLine(q.Title.ToString());
//Console.WriteLine(q.Body.ToString());
}
catch (System.NullReferenceException ex)
{
}
}
}
}
}