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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:13:59+00:00 2026-06-01T01:13:59+00:00

I have dictionaries. First I initialize them. public Dictionary<string, Bitmap> lookup; public Dictionary<string, Bitmap>

  • 0

I have dictionaries. First I initialize them.

    public Dictionary<string, Bitmap> lookup;
    public Dictionary<string, Bitmap> lookup2;
    public Dictionary<string, Bitmap> lookup3;

Then dictionaries are loaded on button_click event.

    private void button2_Click_1(object sender, EventArgs e)
    {
    lookup = new Dictionary<string, Bitmap>();
    Bitmap l1 = new Bitmap(@"C:\1\1.bmp", true); lookup.Add("1", l1);
    // add hundreds more
    }

the problem is that this code takes up nearly half of my main file space, so I was thinking about creating a separate file to load dictionaries from it.

so I tried to create a separate class (cs) file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace getDictData
{
    class mydict
    {
        public static void loadDict()
        {
            Dictionary<string, Bitmap> lookup = new Dictionary<string, Bitmap>();
            Bitmap l1 = new Bitmap(@"C:\1\1.bmp", true); lookup.Add("1", l1);
        }
    }
}

in the main file I add:

using getDictData

and use it like this:

 private void button2_Click_1(object sender, EventArgs e)
 {
 mydict.loadDict();
 }

nothing seems to be working.. so how do you load methods from different files with C#?

EDIT: I’m using this code to check if something was loaded into a dictionary:

    private void button8_Click(object sender, EventArgs e)
    {
        var targer = lookup.ToList(); // error is thrown here
        string s = targer[0].Key;
        textBox6.Text = "" + s;
    }

the result is always null, no matter how I change the code.

“Value cannot be null. Parameter name: source”

and if I delete dictionary initialization from main file I’m getting

“The name ‘lookup’ does not exist in the current context”

  • 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-01T01:14:00+00:00Added an answer on June 1, 2026 at 1:14 am

    The trouble you are facing is something very trivial. Indeed you can write functions in different files, classes etc and thats how it has to be done. If you try this, it definitely would work.

    public Dictionary<string, Bitmap> lookup;
    public Dictionary<string, Bitmap> lookup2;
    public Dictionary<string, Bitmap> lookup3;
    
     private void button2_Click_1(object sender, EventArgs e)
     {
         lookup = mydict.loadDict(); //now that you have loaded it.
     }
    

    Your class should be:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;
    
    namespace getDictData
    {
        class mydict
        {
            public static Dictionary<string, Bitmap> loadDict()
            {
                Dictionary<string, Bitmap> lookup = new Dictionary<string, Bitmap>();
                Bitmap l1 = new Bitmap(@"C:\1\1.bmp", true); lookup.Add("1", l1);
                return lookup;
            }
        }
    }
    

    And now,

    private void button8_Click(object sender, EventArgs e)
    {  
        var targer = lookup.ToList(); //hopefully lookup is not null anymore    
    
        if (lookup.Count == 0) //or whatever way you want to validate depending upon the indexing u use
        {
             MessageBox.Show("No valid items"); //or something similar that you dont get index out of bound exception.
             return;
        }
    
        string s = targer[0].Key;
        textBox6.Text = "" + s;
    }
    

    Edit: I guess there are just a few dictionaries to be loaded. You could do this instead to answer your question in comment, but not elegant at all.

    1) Return a list of dictionaries from dictionary loading class:

    Your Dictionary loading class:

       class mydict
       {
           public static List<Dictionary<string, Bitmap>> loadAllDicts()
           {
               List<Dictionary<string, Bitmap>> lookups = new List<Dictionary<string, Bitmap>>();
    
                Dictionary<string, Bitmap> lookup1 = new Dictionary<string, Bitmap>();
                Bitmap l1 = new Bitmap(@"C:\1\1.bmp", true); 
                lookup1.Add("1", l1);
                lookups.Add(lookup1);
    
                Dictionary<string, Bitmap> lookup2 = new Dictionary<string, Bitmap>();
                Bitmap l2 = new Bitmap(@"C:\1\1.bmp", true); 
                lookup2.Add("1", l2);
                lookups.Add(lookup2);
    
                //etc
    
                return lookups;
            }
        }
    

    2) And then

       private void button2_Click_1(object sender, EventArgs e)
       {
            List<Dictionary<string, Bitmap>> lookups = mydict.loadAllDicts();
    
            lookup = lookups[0];
            lookup2 = lookups[1];
            lookup3 = lookups[2];
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my problem: I have two dictionaries with identical structures: Dictionary<string, List<Object>> Existing
I have a List<Dictionary<String, String>> dictionaries . Each dictionary will contain the following keys
I have two dictionaries like Dictionary<String, String> one = new Dictionary<string, string> { {
I have two dictionaries. When I change a value in dictionary 1, the same
I have two existing dictionaries, and I wish to 'append' one of them to
I wrote a serializer (to Byte Array) for dictionaries that have a string key,
I have a very long list of dictionaries with string indices and integer values.
I have 2 arrays. The first is an array of dictionaries from a JSON
first post, so play nice! I have a fairly basic question about Python dictionaries.
I have about 20,000 NSDictionary s. Each dictionary contains three NSString s. The dictionaries

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.