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

The Archive Base Latest Questions

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

I have declared the following Enum: public enum AfpRecordId { BRG = 0xD3A8C6, ERG

  • 0

I have declared the following Enum:

public enum AfpRecordId
{
    BRG = 0xD3A8C6,
    ERG = 0xD3A9C6
}

and i want to retrieve the enum object from is value:

private AfpRecordId GetAfpRecordId(byte[] data)
{
    ...                    
}

Call Examples:

byte[] tempData = new byte { 0xD3, 0xA8, 0xC6 };
AfpRecordId tempId = GetAfpRecordId(tempData);

//tempId should be equals to AfpRecordId.BRG

I would also like to use linq or lambda, only if they can give better or equals performance.

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

    Simple:

    • Convert the byte array into an int (either manually, or by creating a four byte array and using BitConverter.ToInt32)
    • Cast the int to AfpRecordId
    • Call ToString on the result if necessary (your subject line suggests getting the name, but your method signature only talks about the value)

    For example:

    private static AfpRecordId GetAfpRecordId(byte[] data)
    {
        // Alternatively, switch on data.Length and hard-code the conversion
        // for lengths 1, 2, 3, 4 and throw an exception otherwise...
        int value = 0;
        foreach (byte b in data)
        {
            value = (value << 8) | b;
        }
        return (AfpRecordId) value;
    }
    

    You can use Enum.IsDefined to check whether the given data is actually a valid ID.

    As for performance – check whether something simple gives you good enough performance before you look for something faster.

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

Sidebar

Related Questions

I have the following enum declared: public enum TransactionTypeCode { Shipment = 'S', Receipt
I have declared the following enum type in which I want the first member
I have the following enum public enum TESTENUM { Value1 = 1, Value2 =
I have declared the following method: private void mockInvokeDBHandler(Map<String, Object>... rows) { List<Map<String, Object>>
So, say I have the following enum declaration: public class WatchService implements Runnable {
I have some C++ code, in which the following enum is declared: enum Some
I have declared the following extension method: public static T FindAncestor<T>(DependencyObject obj) where T
In following program . I have one doubt. I have declared one global variable
I have a project that requires the following. Four arrays will be declared in
I have declared an enum in my server code, and would like my client

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.