당신은 안전하지 않은 코드로 그렇게 할 수 있습니다. 안전하지 않은 코드를 사용할 수없는 상황에 처한 경우 효과가 떨어집니다.
편집 : (당신은 할 수
[StructLayout(LayoutKind.Explicit)]
struct Int32SingleUnion
{
[FieldOffset(0)]
int i;
[FieldOffset(0)]
float f;
internal Int32SingleUnion(int i)
{
this.f = 0; // Just to keep the compiler happy
this.i = i;
}
internal Int32SingleUnion(float f)
{
this.i = 0; // Just to keep the compiler happy
this.f = f;
}
internal int AsInt32
{
get { return i; }
}
internal float AsSingle
{
get { return f; }
}
}
:이 내가 MiscUtil에 사용했던 또 다른 대안은 원래의 예처럼 더 많은 일을하기 위해 C 같은 "노동 조합"을 사용하지만 사용자 정의 구조체를 통해 길고 두 배로 똑같이하십시오.)
만약 내가이 질문을 오해하지 않았다면, C#에서'return Convert.ToSingle (result); '처럼 할 수 있습니다. –