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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:23:23+00:00 2026-05-29T17:23:23+00:00

I am doing encoding and decoding using reflection. when I read the this.GetType().Getfields(), in

  • 0

I am doing encoding and decoding using reflection.
when I read the this.GetType().Getfields(), in some machines it is returned in a random order, I need to order them back to do the encoding and decoding correctly.

Can I sort the array returned from this.GetType().GetFields() using FieldInfo.FieldHandle
Like this :

        FieldInfo[] infos = GetType().GetFields();
        Array.Sort(infos, delegate(FieldInfo first, FieldInfo second)
        {
            return first.FieldHandle.Value.ToInt32().CompareTo(second..Value.ToInt32());
        });

is it the correct way.
I mean Now it is give me correct ordering, but i don’t know if it will do every time I call it(timing or time of processing issues).

is there any problem may happen in the future from this code.

my question is about using “FieldHandle” in ordering.

if it is not stable what can I use instead of it.

Regards,

  • 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-29T17:23:42+00:00Added an answer on May 29, 2026 at 5:23 pm

    A much simpler way would be to use Linq:

    FieldInfo[] infos = typeof(string).GetFields()
       .OrderBy(fi => fi.FieldHandle.Value.ToInt32()).ToArray();
    

    But remember that the FieldHandle isn’t necessarily a stable or meaningful field to sort by.

    EDIT: I see you’re asking about using FieldHandle to sort by, in general. In that case, the answer is YES, you WILL have problems with it in the future. The FieldHandle is a pointer to a structure in memory. This memory location is RANDOMLY allocated. Every time you run your program, you’ll get a different set of FieldHandles, and your sorting will be different. This isn’t a unique and persistent ID of the field, it’s just a memory pointer.

    What are you trying to accomplish with this sorting? Maybe we can suggest some alternatives.

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

Sidebar

Related Questions

I am really lost in all the encoding/decoding issues with Python. Having read quite
I have a issue while doing some encoding with the string. It returns all
I'm doing some work using the JavaMail API, and I've run across encodings which
What am I doing wrong? Am I encoding/decoding the enum type properly? GameSettings interface:
I'm writing an encoding/decoding .COM program using Huffman algorithm for dos 8086 (16-bit tasm
Doing something like this at the moment: try { while ((bytesRead = clientStream.Read(data, 0,
Using getJSON to retrieve some data which I am utf8 encoding on the server-side
I'm doing one research on video encoding tools for flv. I tested flvtool2 and
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing some jquery animation. I have certain divs set up with an attribute of

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.