Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3331888
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:37:49+00:00 2026-05-17T23:37:49+00:00

i have declared a variable in the class ‘Main’ with name ‘context2’. But i

  • 0

i have declared a variable in the class ‘Main’ with name ‘context2’. But i cannot use the variable inside the function ‘Main_Load’. what am i doing wrong ?

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)
                {

                }

            }

        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:37:50+00:00Added an answer on May 17, 2026 at 11:37 pm

    Implicit typing doesn’t work with fields; it only works with local variables.

    I think this is what your real intention is:

    ApiContext context2 = new ApiContext(apiKey);
    
    public Main(String GravatarURL, User user)
    {
       context2.Initialize(false);
       ...
    }
    

    In the highly unlikely case that ApiContext is some sort of fluent-interface for which ApiContext.Initialize(bool)returns a differentApiContextobject, this should be what you want:

    ApiContext context2 = new ApiContext(apiKey).Initialize(false); 
    

    although it would be much clearer if you did:

    ApiContext context2;
    
    public Main(String GravatarURL, User user)
    {
       context2 = new ApiContext(apiKey).Initialize(false);
       ...
    }
    

    I really doubt that, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a boolean variable declared at the top of a class and when
WorkAround: I have declared a class level Public static variable and initialized with a
I have a variable declared like this in a class: Entity *array[BOARD_SIZE][BOARD_SIZE]; I need
This is a contrived example, but lets say I have declared objects: CustomObj fooObj;
I have two classes declared like this: class Object1 { protected ulong guid; protected
In the unit below I have a variable declared in the IMPLEMENTATION section -
I have a class with an __init__ function. How can I return an integer
Let's say I have the following simple table variable: declare @databases table ( DatabaseID
In my C# source code I may have declared integers as: int i =
I have a COM object written using the MS ATL library. I have declared

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.