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 8556519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:22:14+00:00 2026-06-11T15:22:14+00:00

I try to use data after I downloaded it from an API. Example of

  • 0

I try to use data after I downloaded it from an API. Example of my code:

private int id;
public MainPage()
{
    InitializeComponent();
    SomeFunction();
}
public void SomeFunction()
{
    DownloadFromAPI("url to api");
    MessageBox.Show(id.ToString());  //<< Returns 0
}
public void DownloadFromAPI(DownloadStringCompletedEventArgs url)
{
    //code to retrieve data (singel id)
    id = Int16.Parse(data);
    MessageBox.Show(id.ToString());  //<< Returns the correct number, like 14
    test();
}
private void test()
{
    MessageBox.Show(id.ToString());  //<< Even Returns the correct number 14 
}

How is it possible to load the id information after DownloadFromAPI("url to api"); is finished. so i get the right number (14) instead of 0?

  • 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-06-11T15:22:16+00:00Added an answer on June 11, 2026 at 3:22 pm

    I suspect your method actually looks like this:

    public void DownloadFromAPI(...)
    {
        int id = Int16.Parse(data);
        MessageBox.Show(id.ToString());  //<< Returns the correct number, like 14
    }
    

    That’s declaring a new local variable within the method, rather than assigning a value to the instance variable.

    However, personally, I’d often prefer to write the method to return the value instead:

    public int DownloadFromApi(...)
    {
        return Int16.Parse(data);
    }
    

    Of course if this really is natural state within the object, it may make sense – but often it can be simpler to write code which just computes a value and returns it, than getting into mutation territory.

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

Sidebar

Related Questions

I use kohana and when you try to fetch data from database it returns
I try use a integer array in java with the code below: public static
I use in my code calls to HttpWebRequest.BeginGetResponse() method to get data from my
I am try to use an external website to get data but what I
I have a problem when try to use hashtable with large data. I have
I try to use logman instead of DDK tracelog for colecting *.etl data produced
I try use string as a regular expression pattern but I've following errors PHP
I try to use a variable in my kshell script but can't get a
I try to use the great particle emitter which Michael Daley build for his
I try to use SQL SERVER VIEW within RIA Services. So I created some

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.