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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:18:15+00:00 2026-05-23T08:18:15+00:00

I’m a bit confused with the Explicit enumeration conversions what does that really mean..

  • 0

I’m a bit confused with the Explicit enumeration conversions what does that really mean..

I’m trying to use a Enumeration to do a pretty cool expected behavior and act as a nice magic number replacement at the same time.. kill two bird with one stone.

I got something like this.

public enum Size {Bare, Fixed, VariableByte, VariableShort};

The beauty in the expected behavior is in this protocol i’m working with.

If I just send a packet without any opcode command it’s called a Bare packet meaning the buffer size is just payload similar to

new byte[payloadSize]; but [payloadSize+Bare] would be equivalent

byte[] buffer = new byte[payloadSize+Bare];   //Bare = 0

If the packet is Fixed.. it contains a OpCode which has to be appended in front. so it’s

new byte[1+payload];

byte[] buffer = new byte[payloadSize+Fixed] //Fixed of course = 1.

VariableByte contains a opcode in front and a byte to represent the size of the packet. This is for packets in the 255 size range etc.. which is

new byte[2+payload];

VariableShort is same as above except the packet size can be a word 65535 payload. which is

I may be causing myself problems in the future if the protocol ever changes then I may have to assign values to the enum in the future to fix problems but for now it’s a valid enum which starts at index=0 [after googling I heard that if you don’t start a enum at the default value of 0] it’s not a correct valid enum.. lol idk what that means.. probably puts stress on enum operation.

Anyways back to my question.

as I already know I can do such as

int Ret = (int)Size.Bare;

or

int Ret = Convert.ToInt32(Size.Bare);
byte[] packet = new byte[payloadSize+Ret]

or best.

byte[] packet = new byte[payloadSize+(int)Size.Bare]

I’m trying to avoid as much amount of lines of coding as possible maybe even increase performance.

I was reading MSDN and found you can do this.. I haven’t really discovered it’s purpose but I am predicting what it may mean..

public enum Size : int {Bare, Fixed, VariableByte, VariableShort};

I assume this would be possible

byte[] packet = new byte[payloadSize+Size.Fixed];

byte[] packet = new byte[payloadSize+Size.VariableShort];

etc…

But unfortunately it isn’t and I get this old error

Operator ‘+’ cannot be applied to operands of type ‘int’ and Packet.Size

so I wonder what does it really mean to put a byte casting in front of a Enum?
As it really doesn’t make me do any cool things like I attempted above.

Does it just limit it to be casted to byte only? or something or it’s plain old just for looks?

Doesn’t seem to limit anything.

byte[] buffer = new byte[payloadZie+(byte)Size.Fixed];

Still works and of course int != byte.

Just wondering whats this could mean.
Thanks sorry if I ask too much questions :\
You guys provide better answers then any forum period.

  • 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-23T08:18:16+00:00Added an answer on May 23, 2026 at 8:18 am

    An enum provides for the switch statements and comparisons where you are comparing logical states or values. (i.e ConnectionState == Connected vs ConnectionState == 1).

    What you want here are integer values. You can however write a class with public fields and/or properties to do what you want. Make it static and you will provide the compiler/CLR with a good optimisation as well.

    public static class Sizes
    {
        public static readonly int Bare = 0;
        public static readonly int VariableByte = 65536;
    }
    

    You can use them the same way but now as Sizes.Bare is an integer with value 0 you can use it in an addition.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.