ByteArray.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Collections.Generic;
  2. namespace S7.Net.Types
  3. {
  4. class ByteArray
  5. {
  6. List<byte> list = new List<byte>();
  7. public byte this[int index]
  8. {
  9. get => list[index];
  10. set => list[index] = value;
  11. }
  12. public byte[] Array
  13. {
  14. get { return list.ToArray(); }
  15. }
  16. public int Length => list.Count;
  17. public ByteArray()
  18. {
  19. list = new List<byte>();
  20. }
  21. public ByteArray(int size)
  22. {
  23. list = new List<byte>(size);
  24. }
  25. public void Clear()
  26. {
  27. list = new List<byte>();
  28. }
  29. public void Add(byte item)
  30. {
  31. list.Add(item);
  32. }
  33. public void AddWord(ushort value)
  34. {
  35. list.Add((byte) (value >> 8));
  36. list.Add((byte) value);
  37. }
  38. public void Add(byte[] items)
  39. {
  40. list.AddRange(items);
  41. }
  42. public void Add(IEnumerable<byte> items)
  43. {
  44. list.AddRange(items);
  45. }
  46. public void Add(ByteArray byteArray)
  47. {
  48. list.AddRange(byteArray.Array);
  49. }
  50. }
  51. }