fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using System.Runtime.InteropServices;
  7.  
  8. namespace 配列の型変換__
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. UnionReference UR = new UnionReference();//下の方に定義あり。
  15.  
  16. UR.ByteArray = new byte[128];
  17. UR.ShortArray[0] = 511;
  18.  
  19. Console.WriteLine("ByteArray:{0},ShortArray:{1}", UR.ByteArray.Count(), UR.ShortArray.Count());
  20. UR.ByteArray = null;
  21.  
  22. UR.ShortArray = new short[128];
  23. UR.ByteArray[4] =128 ;
  24.  
  25. Console.WriteLine("ByteArray:{0},ShortArray:{1}", UR.ByteArray.Count(), UR.ShortArray.Count());
  26. return;
  27.  
  28. }
  29.  
  30. //static void Main(string[] args)
  31. //{
  32. // short[] Ary = new short[] { 1, 2, 3, 4, 5, 6, 7, 8 };
  33. // byte[] Ary2 = Ary;//不可
  34. //}
  35. }
  36.  
  37. [System.Runtime.InteropServices.StructLayout(LayoutKind.Explicit)]
  38. struct UnionReference
  39. {
  40. [System.Runtime.InteropServices.FieldOffset(0)]
  41. public byte[] ByteArray;
  42. [System.Runtime.InteropServices.FieldOffset(0)]
  43. public short[] ShortArray;
  44. }
  45. }
Runtime error #stdin #stdout 0.03s 39488KB
stdin
Standard input is empty
stdout
System.Byte[] doesn't implement interface System.Collections.Generic.IEnumerable<System.Int16>