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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:44:51+00:00 2026-05-31T12:44:51+00:00

This program is meant to read in a csv file and create a dictionary

  • 0

This program is meant to read in a csv file and create a dictionary from it, which is then used to translate a word typed into a textbox (txtINPUT) and output the result to another textbox (txtOutput).

The program doesnt translate anything and always outputs “No translation found.”
I’ve never used the dictionary class before so I dont know where the problem is coming from.

Thanks for any help you can give me.

    Dictionary<string, string> dictionary; 

    private void CreateDictionary()
    {
        //Load file
        List<string> list = new List<string>();
        using (StreamReader reader = new StreamReader("dictionarylist.csv"))
        {
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                //Add to dictionary
                dictionary = new Dictionary<string, string>();
                string[] split = line.Split(',');
                dictionary.Add(split[0], split[1]);
            }
        }
    }
        private void btnTranslate_Click(object sender, EventArgs e)
    {
        CreateDictionary();

        string outputString = null;
        if (dictionary.TryGetValue(txtInput.Text, out outputString))
        {
            txtOutput.Text = outputString; 
        }
        else
        {
            txtOutput.Text = ("No translation found");
        }

    }
  • 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-31T12:44:52+00:00Added an answer on May 31, 2026 at 12:44 pm

    You are creating a new instance of a Dictionary each loop cycle, basically overwriting it each time you read a line. Move this line out of the loop:

    // Instantiate a dictionary
    var map = new Dictionary<string, string>();
    

    Also why not load dictionary one time, you are loading it each button click, this is not efficient.

    (>=.NET 3) The same using LINQ ToDictionary():

    usign System.Linq;
    var map = File.ReadAllLines()
                  .Select(l =>
                   {
                        var pair = l.Split(',');
                        return new { First = pair[0], Second = pair[1] }
                   })
                  .ToDictionary(k => k.First, v => v.Second);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got this read file code from microsoft @C:\Users\computing\Documents\mikec\assignment2\task_2.txt That works fine when
This program is meant to generate a dynamic array, however it gives an access
This program I'm doing is about a social network, which means there are users
This program stores pairs in a map, counting the number of times a word
This program reads emails (really just a .txt file structured like an email) and
This code runs fine but the for statement by the meant to read back
I've been tasked with writing a c# program which is meant to do the
I have to read the headers of the file in order to create a
I have this program, but cin in randomly skips.. I mean sometimes it does,
Strange program hang, what does this mean in debug? After attaching windbg I found

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.