Unions in c#
hey c# experts, I want to know how to create unions in c# & work with them. can anyone give me a sample code?
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mike GoldRank #50 · 30.6K reputationPosted Jun 11, 2007, 10:33 PM EDT
http://msdn2.microsoft.com/En-US/library/acxa5b99(VS.80).aspx
Best,
AlanRank #669 · 3.6K reputationPosted Jun 12, 2007, 1:42 AM EDT
http://msdn2.microsoft.com/en-us/library/ya9bz4ha(vs.80).aspx
If you don't mind using 'unsafe' code, then in C# 2.0 you can also use a fixed sized char buffer to represent a string within a union, as the buffer (rather than a pointer thereto) is actually embedded into the struct's memory and so is treated as a value type:
http://msdn2.microsoft.com/en-us/library/zycewsya(VS.80).aspx
Mike GoldRank #50 · 30.6K reputationPosted Jun 12, 2007, 9:45 AM EDT
Thanks for pointing that out.