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

  • Home
  • SEARCH
  • 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 6032845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:23:45+00:00 2026-05-23T05:23:45+00:00

Possible Duplicate: C++ union in C# Code in C: typedef struct _EVENT_HEADER { USHORT

  • 0

Possible Duplicate:
C++ union in C#

Code in C:

typedef struct _EVENT_HEADER {
USHORT              Size;                   // Event Size
USHORT              HeaderType;             // Header Type
USHORT              Flags;                  // Flags
USHORT              EventProperty;          // User given event property
ULONG               ThreadId;               // Thread Id
ULONG               ProcessId;              // Process Id
LARGE_INTEGER       TimeStamp;              // Event Timestamp
GUID                ProviderId;             // Provider Id
EVENT_DESCRIPTOR    EventDescriptor;        // Event Descriptor
union {
    struct {
        ULONG       KernelTime;             // Kernel Mode CPU ticks
        ULONG       UserTime;               // User mode CPU ticks
    } DUMMYSTRUCTNAME;
    ULONG64         ProcessorTime;          // Processor Clock 
                                            // for private session events
} DUMMYUNIONNAME;
GUID                ActivityId;             // Activity Id

} EVENT_HEADER, *PEVENT_HEADER;

I converted anything but the union. How to convert it to C#?

  • 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-23T05:23:45+00:00Added an answer on May 23, 2026 at 5:23 am

    C# doesn’t natively support the C/C++ notion of unions. You can however use the StructLayout(LayoutKind.Explicit) and FieldOffset attributes to create equivalent functionality.

    Regarding to union: in the code below you can see that Kernel and ProcessorTime have the same offset. LargeInteger is also a good example of union implementation in C#.

    EventHeader

    [StructLayout(LayoutKind.Explicit)]
    public struct EventHeader
    {
        [FieldOffset(0)]
        public ushort Size;
    
        [FieldOffset(2)]
        public ushort HeaderType;
    
        [FieldOffset(4)]
        public ushort Flags;
    
        [FieldOffset(6)]
        public ushort EventProperty;
    
        [FieldOffset(8)]
        public uint ThreadId;
    
        [FieldOffset(12)]
        public uint ProcessId;
    
        [FieldOffset(16)]
        public LargeInteger TimeStamp;
    
        [FieldOffset(24)]
        public Guid ProviderId;
    
        [FieldOffset(40)]
        public Guid EventDescriptor;
    
        [FieldOffset(52)]
        public uint KernelTime;
    
        [FieldOffset(56)]
        public uint UserTime;
    
        [FieldOffset(52)]
        public ulong ProcessorTime;
    
        [FieldOffset(60)]
        public Guid ActivityId;
    }
    

    LargeInteger

    [StructLayout(LayoutKind.Explicit, Size = 8)]
    public struct LargeInteger
    {
        [FieldOffset(0)]
        public long QuadPart;
    
        [FieldOffset(0)]
        public uint LowPart;
    
        [FieldOffset(4)]
        public uint HighPart;
    }
    

    EventDescriptor

    [StructLayout(LayoutKind.Sequential)]
    public struct EventDescriptor
    {
        public ushort Id;
    
        public byte Level;
    
        public byte Channel;
    
        public byte LevelSeverity;
    
        public byte Opcode;
    
        public ushort Task;
    
        public uint Keyword;
    }
    

    Disclaimer: I just made this code. Didn’t test it. The code may have errors.

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

Sidebar

Related Questions

Possible Duplicate: A question about union in C Assuming the following code: #include <stdio.h>
Possible Duplicate: How do I find the size of a struct? Struct varies in
Possible Duplicate: C++ struct sorting Is it possible to sort a vector in C++
Possible Duplicate: Difference between a Structure and a Union in C I see this
Possible Duplicate: Can you write object oriented code in C? Hi, can someone point
Possible Duplicate: C: Where is union practically used? I know the concept of union
Possible Duplicate: How to find the kth smallest element in the union of two
Possible Duplicate: C/C++: When would anyone use a union? Is it basically a remnant
Possible Duplicate: Disjoint Union in LINQ DUPE : Disjoint Union in LINQ I know
Possible Duplicate: Difference between a Structure and a Union in C I could understand

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.