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

  • Home
  • SEARCH
  • 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 5847887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:46:57+00:00 2026-05-22T12:46:57+00:00

I have declared a class variable in here void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) {

  • 0

I have declared a class variable in here

void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    if (e.Error == null)
    {
        Stream responseStream = e.Result;
        StreamReader responseReader = new StreamReader(responseStream);
        string response = responseReader.ReadToEnd();


        string[] split1 = Regex.Split(response, "},{");
        List<string> pri1 = new List<string>(split1);
        pri1.RemoveAt(0);
        string last = pri1[pri1.Count() - 1];
        pri1.Remove(last);

    }
}

and I want to use the class variable str in this method

void AddPrimaryMarkerGraphics(object sender, getPrimaryListCompletedEventArgs e) 
{
    List<PrimaryClass> primaryList = new List<PrimaryClass>(e.Result);
    PrimaryClass sc = new PrimaryClass();
    for (int a = 0; a <= e.Result.Count - 1; a++)
    {
        string schname = e.Result.ElementAt(a).PrimarySchool;
        string tophonour = e.Result.ElementAt(a).TopHonour;
        string cca = e.Result.ElementAt(a).Cca;
        string topstudent = e.Result.ElementAt(a).TopStudent;
        string topaggregate = e.Result.ElementAt(a).TopAggregate;
        string topimage = e.Result.ElementAt(a).TopImage;

        foreach (string item in str)
        {
            string abc = "[{" + item + "}]";
            byte[] buf = System.Text.Encoding.UTF8.GetBytes(abc);
            MemoryStream ms = new MemoryStream(buf);

            JsonArray users = (JsonArray)JsonArray.Load(ms);

            var members = from member in users
                          //where member["SEARCHVAL"]
                          select member;

            foreach (JsonObject member in members)
            {
                string schname = member["SEARCHVAL"];
                string axisX = member["X"];
                string axisY = member["Y"];
                // Do something...
                string jsonCoordinateString = "{'Coordinates':[{'X':" + axisX + ",'Y':" + axisY + "}]}";
                CustomCoordinateList coordinateList = DeserializeJson<CustomCoordinateList>(jsonCoordinateString);

                GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer_Primary"] as GraphicsLayer;

                for (int i = 0; i < coordinateList.Coordinates.Count; i++)
                {
                    Graphic graphic = new Graphic()
                    {
                        Geometry = new MapPoint(coordinateList.Coordinates[i].X, coordinateList.Coordinates[i].Y),
                        Symbol = i > 0 ? PrimarySchoolMarkerSymbol : PrimarySchoolMarkerSymbol

                    };
                    graphic.Attributes.Add("PrimarySchool", schname);
                    graphic.Attributes.Add("xcoord", axisX);
                    graphic.Attributes.Add("ycoord", axisY);
                    graphicsLayer.Graphics.Add(graphic);
                }
            }
        }
    }
}

That’s where the error shows.

  • 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-22T12:46:57+00:00Added an answer on May 22, 2026 at 12:46 pm

    You’ve almost certainly declared the variable in a method (i.e. as a local variable), instead of directly in the class itself (as an instance variable). For example:

    // Wrong
    class Bad
    {
        void Method1()
        {
            List<string> str = new List<string>();
        }
    
        void Method2()
        {
            foreach (string item in str)
            {
                ...
            }
        }
    }
    
    // Right
    class Good
    {
        private List<string> str = new List<string>();
    
        void Method1()
        {
            str = CreateSomeOtherList();
        }
    
        void Method2()
        {
            foreach (string item in str)
            {
                ...
            }
        }
    }
    

    As a side-note: if you’re very new to C#, I would strongly recommend that you stop working on Silverlight temporarily, and write some console apps just to get you going, and to teach you the basics. That way you can focus on C# as a language and the core framework types (text, numbers, collections, I/O for example) and then start coding GUIs later. GUI programming often involves learning a lot more things (threading, XAML, binding etc) and trying to learn everything in one go just makes things harder.

    • 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
I have two classes declared like this: class Object1 { protected ulong guid; protected
I have two classes: Action and MyAction . The latter is declared as: class
I have a class that offers up a few events. That class is declared
I have a COM object written using the MS ATL library. I have declared
An enum structure declared in its own class is a member variable to the
I have an abstract base class and I want to declare a field or
In my C# source code I may have declared integers as: int i =
This is a contrived example, but lets say I have declared objects: CustomObj fooObj;
I have the following enum declared: public enum TransactionTypeCode { Shipment = 'S', Receipt

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.