using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace unionTest
{
class Program
{
[StructLayout(LayoutKind.Explicit)]
public unsafe struct INT_BYTE
{
[FieldOffset(0)]
public int i;
[FieldOffset(0)]
public fixed byte b[4];
};
static void Main(string[] args)
{
INT_BYTE x1 = new INT_BYTE();
INT_BYTE x2 = new INT_BYTE();
x1.i = 0x12345678;
unsafe
{
for (int k = 0; k < 4; k++)
x2.b[k] = x1.b[k];
}
Console.WriteLine(" x2 = 0x{0:x} ", x2.i);
}
}
}
------------------------------------------------------------------
프로젝트 속성 - 빌드 옵션 변경
'프로젝트' 카테고리의 다른 글
C# string to char, char to string ( 캐릭터, 문자열 변환 ) (퍼옴) (0) | 2017.03.19 |
---|---|
C# Text 파일 읽어서 출력하는 방식 두 가지.(퍼옴) (0) | 2017.03.19 |
c#에서 union 사용하기(3) (0) | 2017.03.02 |
C#에서 union 사용하기(1) (0) | 2017.03.01 |
CO2 가스 센서 - 모니터링 & 설정 (0) | 2017.03.01 |