in Education by
I'm translating a library written in C++ to C#, and the keyword 'union' exists once. In a struct. What's the correct way of translating it into C#? And what does it do? It looks something like this; struct Foo { float bar; union { int killroy; float fubar; } as; } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can use explicit field layouts for that: [StructLayout(LayoutKind.Explicit)] public struct SampleUnion { [FieldOffset(0)] public float bar; [FieldOffset(4)] public int killroy; [FieldOffset(4)] public float fubar; } Untested. The idea is that two variables have the same position in your struct. You can of course only use one of them. More informations about unions in struct tutorial

Related questions

0 votes
    I'm translating a library written in C++ to C#, and the keyword 'union' exists once. In a struct ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    In my dll there is a method that I want to export. //Works: extern "C" __declspec(dllexport) // ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    In my dll there is a method that I want to export. //Works: extern "C" __declspec(dllexport) // ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    In my dll there is a method that I want to export. //Works: extern "C" __declspec(dllexport) // ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    In my dll there is a method that I want to export. //Works: extern "C" __declspec(dllexport) // ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I'm trying to PInvoke into this C++ library function: int Initialize(Callback* callback); struct Callback { ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 21, 2022 in Education by JackTerrance
0 votes
    I'm trying to PInvoke into this C++ library function: int Initialize(Callback* callback); struct Callback { ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    How can one get the coordinates of a mouse click inside a panel? For instance I want to be able ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Identify the incorrect pair in every set, correct it and rewrite (a) Iran - Ayatollah Khomeini (b) Afghanistan - ... Soviet Union - Richard Nixon Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
0 votes
    Identify the incorrect pair in every set and correct it. 1. (a) Mao Zedong - Korea (b) Nikita Khrushchev - ... (d) Thailand - SEATO Select the correct answer from above options...
asked Aug 3, 2022 in Education by JackTerrance
0 votes
    Identify the incorrect pair in every set, correct it and rewrite. 1. (a) Soviet Union - Brezhnev (b) Egypt - Nasser ... (c) NAM - USA Select the correct answer from above options...
asked Aug 3, 2022 in Education by JackTerrance
+1 vote
    Which operator can be used to access union elements if union variable is a pointer variable in C Programming ?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    President of Soviet Union who implemented Perestroika' and Glasnost' ....... (a) Nikita Khrushchev (b) Mikhail ... Molotov (d) Vladimir Lenin Please answer the above question....
asked Aug 20, 2022 in Education by JackTerrance
0 votes
    The trade union movement in India has background of ………………… . (a) freedom struggle (b) globalisation (c) prestigious past (d) industrialisation Please answer the above question....
asked Aug 14, 2022 in Education by JackTerrance
0 votes
    What are the demands of Trade Union Movement? Please answer the above question....
asked Aug 14, 2022 in Education by JackTerrance
...