# CSharp - NaN のダンプ
###### tags: `C#`, `.net`
~~~cs
using System.IO;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Explicit)]
public struct NaNData
{
[FieldOffset(0)]
public float floatValue;
[FieldOffset(0)]
public double doubleValue;
[FieldOffset(0)]
public byte byte0;
[FieldOffset(1)]
public byte byte1;
[FieldOffset(2)]
public byte byte2;
[FieldOffset(3)]
public byte byte3;
[FieldOffset(4)]
public byte byte4;
[FieldOffset(5)]
public byte byte5;
[FieldOffset(6)]
public byte byte6;
[FieldOffset(7)]
public byte byte7;
}
class Program
{
static void Main(string[] args)
{
NaNData nan = new NaNData();
nan.floatValue = float.NaN;
File.WriteAllBytes( "floatNaN.bin", new byte[] {
nan.byte0,
nan.byte1,
nan.byte2,
nan.byte3,
});
nan.doubleValue = double.NaN;
File.WriteAllBytes("doubleNaN.bin", new byte[] {
nan.byte0,
nan.byte1,
nan.byte2,
nan.byte3,
nan.byte4,
nan.byte5,
nan.byte6,
nan.byte7,
});
}
}
~~~