I created an application that stores byte arrays in my SQLiteDatabase. This same application also selects the byte arrays from the database every 'x' seconds.
我创建了一个在我的SQLiteDatabase中存储字节数组的应用程序。同样的应用程序还每隔'x'秒从数据库中选择字节数组。
The dataflow of my application is as follow:
我的应用程序的数据流如下:
Application - > SQLiteDatabase -> Application
应用程序 - > SQLiteDatabase - > Application
My question is:
我的问题是:
How do I fill one byte array with all the incoming byte arrays from the SQLiteDatabase?
如何使用SQLiteDatabase中的所有传入字节数组填充一个字节数组?
For example:
例如:
Byte[] Data;
Needs to be filled with the following byte array:
需要填充以下字节数组:
Byte[] IncomingData;
IncomingData is constantly being filled by the SQLiteDatabase.
SQLiteDatabase不断填充IncomingData。
Data needs to be filled with IncomingData constantly.
数据需要不断填充IncomingData。
Can someone help me out?
有人可以帮我吗?
2 个解决方案
#1
4
Just use Concat
:
只需使用Concat:
data1.Concat(IncomingData);
You'll need to add the System.Linq
namespace reference.
您需要添加System.Linq命名空间引用。
#2
4
There are a few approaches you can take.
您可以采取一些方法。
- Use a
List<byte>
andList.AddRange
-
使用List
和List.AddRange - Use LINQ's
Enumerable.Concat
- 使用LINQ的Enumerable.Concat
- Use
Array.Copy
and do it all manually - 使用Array.Copy并手动完成所有操作
Of the three, if possible go with the List
as it will (likely) reduce the amount of array copying required. This is what List's are made for, they use an array behind the scenes with a certain capacity, it starts at 4 and doubles when it hits the capacity. The capacity can even be set to some large number with the list.Capacity
property or the constructor that takes an int
much like you can with an array. You can always bring the list back using List.ToArray
.
在这三个中,如果可能的话,请使用List(因为它)(可能)减少所需的阵列复制量。这就是List的用途,它们在幕后使用具有一定容量的阵列,从4开始,在达到容量时加倍。使用list.Capacity属性或带有int的构造函数甚至可以将容量设置为某个大数字。您始终可以使用List.ToArray返回列表。
Enumerable.Concat will likely only create an array of the minimum size, meaning a new array needs to be created every time you get some more byte
s.
Enumerable.Concat可能只会创建一个最小大小的数组,这意味着每次获得更多字节时都需要创建一个新数组。
#1
4
Just use Concat
:
只需使用Concat:
data1.Concat(IncomingData);
You'll need to add the System.Linq
namespace reference.
您需要添加System.Linq命名空间引用。
#2
4
There are a few approaches you can take.
您可以采取一些方法。
- Use a
List<byte>
andList.AddRange
-
使用List
和List.AddRange - Use LINQ's
Enumerable.Concat
- 使用LINQ的Enumerable.Concat
- Use
Array.Copy
and do it all manually - 使用Array.Copy并手动完成所有操作
Of the three, if possible go with the List
as it will (likely) reduce the amount of array copying required. This is what List's are made for, they use an array behind the scenes with a certain capacity, it starts at 4 and doubles when it hits the capacity. The capacity can even be set to some large number with the list.Capacity
property or the constructor that takes an int
much like you can with an array. You can always bring the list back using List.ToArray
.
在这三个中,如果可能的话,请使用List(因为它)(可能)减少所需的阵列复制量。这就是List的用途,它们在幕后使用具有一定容量的阵列,从4开始,在达到容量时加倍。使用list.Capacity属性或带有int的构造函数甚至可以将容量设置为某个大数字。您始终可以使用List.ToArray返回列表。
Enumerable.Concat will likely only create an array of the minimum size, meaning a new array needs to be created every time you get some more byte
s.
Enumerable.Concat可能只会创建一个最小大小的数组,这意味着每次获得更多字节时都需要创建一个新数组。