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

The Archive Base Latest Questions

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

I’m still relatively new to C# and the answer to this is probably pretty

  • 0

I’m still relatively new to C# and the answer to this is probably pretty obvious, but I’m struggling to solve it

I have an enum defined as follows:

enum Request {
    None = 0,
    GetData,
    SendData,
    some other values...
};

I then have two variables both defined as type Request as follows

Request currentRequest; // This is a class member variable
Request request; // This is a local variable within a method.

The first variable is assigned using currentRequest = Request.GetData;
The second local variable request is assigned using request = (Request)data, where data is byte of value 1 (as the value is being decoded from a buffer of USB data being received). I don’t know if this is relevant but mention it just in case.

I want to compare them within the method in which the second variable is declared, I originally did it like this:

if(request != currentRequest)
{
    // Throw an exception
}

This works most of the time, but occaisionally the exception is thrown because the two values don’t equate, however when I check them in the debugger they are both equal to Request.GetData. This got me thinking that the variables may be pointers to objects rather than values so I tried also using…

!request.Equals(currentRequest)

and

request.CompareTo(currentRequest)!=0

and similarly both of these work most of the time but occaisionally fail even though when the values are checked in the debugger they are both Request.GetData.

What’s really confused me is that it works most of the time, just fails occaisionally – I’d expect it to either work or not work consistently.

Any ideas?

  • 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-26T00:26:28+00:00Added an answer on May 26, 2026 at 12:26 am

    No, if the variables are genuinely of type Request then that’s a value type, and using == should be absolutely fine.

    I suspect that the debugger is showing you something slightly odd. I suggest you make the exception include both request and currentRequest to show you what’s going on.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.