© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
25 replies
SWEETPONY

✅ How to serialize IEnumerable<T> to json?

I have following:
public IReadOnlyList<MessageQueueConsumeResultHeader>? Headers { get; init; }

public abstract class MessageQueueConsumeResultHeader
  {
    public abstract string Key { get; }

    public abstract byte[] GetValueBytes();

    public override string ToString()
    {
      return this.Key + " (" + string.Join<byte>(",", (IEnumerable<byte>) this.GetValueBytes()) + ")";
    }
  }
public IReadOnlyList<MessageQueueConsumeResultHeader>? Headers { get; init; }

public abstract class MessageQueueConsumeResultHeader
  {
    public abstract string Key { get; }

    public abstract byte[] GetValueBytes();

    public override string ToString()
    {
      return this.Key + " (" + string.Join<byte>(",", (IEnumerable<byte>) this.GetValueBytes()) + ")";
    }
  }


and I want to get following:

"
{
"Key": "GetValueBytes()",
...
}
"

how can I do it?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Serialize a JsonDocument/JsonElement with STJ
C#CC# / help
3y ago
Newtonsoft JsonConverter to replicate the serialization of the JsonObjectAttribute on an IEnumerable
C#CC# / help
4y ago
Implementing IEnumerable<T>
C#CC# / help
3y ago
.NET8 Serialize class as JSON
C#CC# / help
2y ago