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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:54:26+00:00 2026-05-23T09:54:26+00:00

I am trying to read 2 values in a binary file and put the

  • 0

I am trying to read 2 values in a binary file and put the 1st value in text box 3 and the 2nd value in text box 4. The 2 values that need to be read from file were created with text boxes 1 and 2 and saved to file with the 1st button. On click of button 2 it is supposed to read the file and put the values in the right spots. I am not sure if it is not reading correctly or if it is not writing correctly. When I click the button to read and display the boxes show this:
System.Collections.Generic.List`1[test.Form1+ore]

Code as follows:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace test
{

public partial class Form1 : Form
{
    [Serializable]
    public class ore
    {
        public float Titan;
        public float Eperton;
    }
    ore b1 = null;
    ore b2 = null;



    public Form1()
    {
        InitializeComponent();

        b2 = new ore();
        b1 = new ore();
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        // 1st text box input is float
        float tempFloat;


        if (float.TryParse(textBox1.Text, out tempFloat))
        {
            b1.Titan = tempFloat;
        }
        else
            MessageBox.Show("uh oh");



    }


    private void textBox2_TextChanged(object sender, EventArgs e)
    {
        // 2nd text box input is float
        float tempFloat;
        if (float.TryParse(textBox1.Text, out tempFloat))
        {
            b2.Eperton = tempFloat;
        }
        else
            MessageBox.Show("uh oh");


    }


    private void button1_Click(object sender, EventArgs e)
    {
        // supposed to save list to file 
        List<ore> oreData = new List<ore>();
        oreData.Add(b1);
        oreData.Add(b2);

        FileStream fs = new FileStream("ore.dat", FileMode.Create);
        BinaryFormatter bf = new BinaryFormatter();
        bf.Serialize(fs, oreData);
        fs.Close();
    }

    private void textBox3_TextChanged(object sender, EventArgs e)
    {
        // 3rd text box 
    }

    private void textBox4_TextChanged(object sender, EventArgs e)
    {
        //4th text box
    }

    List<ore> books = new List<ore>(); // create list
    private void button2_Click(object sender, EventArgs e)
    {
        FileStream fs = new FileStream("ore.dat", FileMode.Open);
        BinaryFormatter bf = new BinaryFormatter();
        List<ore> books = (List<ore>)bf.Deserialize(fs);
        fs.Close();

        if (books.Count > 1)
        {

            textBox3.Text = books.ToString();//update the 3rd text box
            textBox4.Text = books.ToString();//update the 4th text box

        }
    }
}
}
  • 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-23T09:54:26+00:00Added an answer on May 23, 2026 at 9:54 am

    I wondering if you have really asked for what you want, because you effectively answer your own question in your comment…

    List<ore> books = new List<ore>(); // create list
    private void button2_Click(object sender, EventArgs e)
    {
        FileStream fs = new FileStream("ore.dat", FileMode.Open);
        BinaryFormatter bf = new BinaryFormatter();
        List<ore> books = (List<ore>)bf.Deserialize(fs);
        fs.Close();
    
        if (books != null)
        {
            if (books.Count > 0)
                textBox3.Text = books[0].SomeProperty.ToString();//update the 3rd text box
            if (books.Count > 1)
                textBox4.Text = books[1].SomeProperty.ToString();//update the 4th text box
    
        }
    }
    

    Note the use of SomeProperty – this is because each item in books is an instance of the object ore, so you will need to substitute the appropriate property (Titan or Eperton) from ore in place of my SomeProperty place holder.. If you just do a ToString() on ore then you will get back the name of the type as a string, rather than any individual value in it – unless you have overridden the ToString().

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

Sidebar

Related Questions

I am trying to read a binary file from a program that writes a
I'm trying to read specific values from the text file (below): Current Online Users:
I'm trying to read a value from a file and use it in a
I'm trying to read a .doc file into a database so that I can
I am trying to read a single file from a java.util.zip.ZipInputStream , and copy
I am trying to read ASCII text response from a tcp open streaming socket
I am trying to read an XML-file from another server. However the the company
I'm trying to read a binary file (which represents a matrix in Matlab) in
I have a binary file of unknown format that I need to be able
I am trying to read a binary file and parse the bytes I have

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.