Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

What is the C# equivalent of the following C++ code?

This topic is 2506 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


char* trailFlags; // array of flag bits for trail points
.....

bool someBool = CalculateBool();

trailFlags[index] = someBool ? 2 : 0;


I'm unsure as to how the integer value of 2 or 0 is stored as a flag bit char in C#. 0 appears to be stored as '0x002f6020' in C++.

How would I do the same in C#?

Share this post


Link to post
Share on other sites
Advertisement
This should work the exact same way in C#. I'd wager you're looking at the value of trailFlags rather than the value of trailFlags[index] - these are not the same. trailFlags is the memory location that the data is stored at, trailFlags[index] is the actual data.

Share this post


Link to post
Share on other sites
Hidden
in C# you can use pointers but unless you need to typesafe arrays are the better choice


int[] trailFlags = new int[flagLength];
bool someBool = CalculateBool();
trailFlags[index] = someBool ? 2 : 0;

Share this post


Link to post

[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

I'd wager you're looking at the value of trailFlags rather than the value of trailFlags[index] - these are not the same[/font]


[color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif]

[/quote]

[/font]

I see now. My C++ experience is 'null'. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!