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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:16:19+00:00 2026-06-10T04:16:19+00:00

I use C# .net 4.0 and don’t see any possible way to do it,

  • 0

I use C# .net 4.0 and don’t see any possible way to do it, but maybe you know? 🙂
I do my serialization in that way:

public static void SaveCollection<T>(string file_name, T list)
{
    BinaryFormatter bf = new BinaryFormatter();
    FileStream fs = null;

    try
    {
        fs = new FileStream(Application.StartupPath + "/" + file_name, FileMode.Create);
        bf.Serialize(fs, list);
        fs.Flush();
        fs.Close();
    }
    catch (Exception exc)
    {
        if (fs != null)
            fs.Close();

        string msg = "Unable to save collection {0}\nThe error is {1}";
        MessageBox.Show(Form1.ActiveForm, string.Format(msg, file_name, exc.Message));
    }
}
  • 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-10T04:16:21+00:00Added an answer on June 10, 2026 at 4:16 am

    So, let’s say you use actually know in advance the size of your object graph, which itself may be difficult, but let’s just assume you do :). You could do this:

    public class MyStream : MemoryStream {
        public long bytesWritten = 0;
        public override void Write(byte[] buffer, int offset, int count) {                
            base.Write(buffer, offset, count);
            bytesWritten += count;
        }
    
        public override void WriteByte(byte value) {
            bytesWritten += 1;
            base.WriteByte(value);
        }
    }
    

    Then you could use it like:

    BinaryFormatter bf = new BinaryFormatter();
    var s = new MyStream();
    bf.Serialize(s, new DateTime[200]);
    

    This will give you the bytes as they are written, so you could calculate the time using that. Note: it’s possible you might need to override a few more methods of the stream class.

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

Sidebar

Related Questions

Are there any USB developers out there who use .NET? I know one way
I don't know how to use Quartz.dll in ASP.NET. Where should we write the
I don't have any idea how to use this class in .net. Anyone wants
I don't use hungarian (str, int) prefixes in .Net, but I still find it
How to use forms authentication without login control.I don't want to use asp.net login
Is there a .NET version of GetPrivateProfileString? (I can use p/invoke, I just don't
Why would you use .NET Remoting over WCF ? I understand that WCF has
I want to use Net::SSH::Expect in my unix box but unfortunately, it is not
We use .net binary serialization right now to serialize data to persist. It does
I know it's a bit close to Can I use .NET 4.0 beta in

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.