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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:09:27+00:00 2026-05-26T13:09:27+00:00

i got a class which holds info about pictures, like filepath, hashvalue, bytes. in

  • 0

i got a class which holds info about pictures, like filepath, hashvalue, bytes.
in another class i got a generic list where i put objects from the class that holds picture info.

that class looks like this:

[Serializable()]
    class PicInfo : ISerializable
    {
        public string fileName { get; set; }
        public string completeFileName { get; set; }
        public string filePath { get; set; }
        public byte[] hashValue { get; set; }

        public PicInfo()
        { }

        public PicInfo(SerializationInfo info, StreamingContext ctxt)
        {
            this.fileName = (string)info.GetValue("fileName", typeof(string));
            this.completeFileName = (string)info.GetValue("completeFileName", typeof(string));
            this.filePath = (string)info.GetValue("filePath", typeof(string));
            this.hashValue = (byte[])info.GetValue("hashValue", typeof(byte[]));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("fileName", this.fileName);
            info.AddValue("completeFileName", this.completeFileName);
            info.AddValue("filePath", this.filePath);
            info.AddValue("hashValue", this.hashValue);
        }
    }

my list is just list<picinfo> pi = new list<picinfo>();
what would be the eaziest way to serialize this list?

  • 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-26T13:09:28+00:00Added an answer on May 26, 2026 at 1:09 pm

    If you want to use BinaryFormatter (which I really don’t advise), you can use:

    [Serializable]
    class PicInfo
    {
        public string fileName { get; set; }
        public string completeFileName { get; set; }
        public string filePath { get; set; }
        public byte[] hashValue { get; set; }
    
        public PicInfo()  { }
    }
    static class Program
    {
        static void Main()
        {
            List<PicInfo> pi = new List<PicInfo>();
            pi.Add(new PicInfo {fileName = "foo.bar", hashValue = new byte[] {1, 2, 3}});
    
            var ser = new BinaryFormatter();
            using (var ms = new MemoryStream())
            {
                ser.Serialize(ms, pi);
                var bytes = ms.ToArray();
            }
        }
    }
    

    If you want to use XmlSerializer (probably preferable IMO), but need the byte[], then:

    public class PicInfo
    {
        public string fileName { get; set; }
        public string completeFileName { get; set; }
        public string filePath { get; set; }
        public byte[] hashValue { get; set; }
    
        public PicInfo()  { }
    }
    static class Program
    {
        static void Main()
        {
            List<PicInfo> pi = new List<PicInfo>();
            pi.Add(new PicInfo {fileName = "foo.bar", hashValue = new byte[] {1, 2, 3}});
    
            var ser = new XmlSerializer(typeof(List<PicInfo>));
            using (var ms = new MemoryStream())
            {
                ser.Serialize(ms, pi);
                var bytes = ms.ToArray();
            }
        }
    }
    

    Personally, I’d use protobuf-net:

    [ProtoContract]
    public class PicInfo
    {
        [ProtoMember(1)]public string fileName { get; set; }
        [ProtoMember(2)]public string completeFileName { get; set; }
        [ProtoMember(3)]public string filePath { get; set; }
        [ProtoMember(4)]public byte[] hashValue { get; set; }
    
        public PicInfo()  { }
    }
    static class Program
    {
        static void Main()
        {
            List<PicInfo> pi = new List<PicInfo>();
            pi.Add(new PicInfo {fileName = "foo.bar", hashValue = new byte[] {1, 2, 3}});
    
            using (var ms = new MemoryStream())
            {
                Serializer.Serialize(ms, pi);
                var bytes = ms.ToArray();
            }
        }
    }
    

    Sizes:

    • BinaryFormatter: 488 bytes
    • XmlSerializer: 251 bytes
    • protobuf-net: 16 bytes
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a class which inherits from a List<MagicBean> . It works well and
I've got a class which implements it's own (de)serialization via XLINQ, and I'd like
I would like to create one class which holds some key values of the
I've got a C++ class which I would like to hold a stream used
I've got a class TMyAwesomeList = class(TObjectList) which holds TAwesomeItem = class(TPersistent) where TAwesomeItem
I've got a class (which extends MovieClip) that loads in an external SWF (made
I've got a controller class which accpets multiple parameters in the ctor which gets
I'm creating an ORM in PHP, and I've got a class 'ORM' which basically
I've got a complex class in my C# project on which I want to
I've got a JPanel class called Board with a static subclass, MouseHanlder, which tracks

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.