簡體   English   中英

如何在特定位置的嵌套字節數組中插入一個字節?

[英]How can I insert a byte into a nested byte array at an specific position?

我在另一個列表(嵌套列表)中有多個字節列表( )。 如何在特定行的特定索引處插入特定字節?

byte ByteToInsert = 1;
int LineNumber = 2;
int IndexInSubList = 3;

// Create top-level list
List<List<byte>> NestedList = new List<List<byte>>();

// Create two nested lists
List<byte> Line1 = new List<byte> { 2, 2, 5, 25 };
List<byte> Line2 = new List<byte> { 3, 7, 8, 35 };

// Add to top-level list
NestedList.Add(Line1);
NestedList.Add(Line2);

// Insert
...

執行插入代碼后,NestedLists應該由兩行組成:

{ 2, 2, 5, 25 }
{ 3, 7, 8, 1, 35 }

我該怎么做?

感謝Hamlet Hakobyan和Marc Gravell♦:

如果要插入一個字節:

NestedList[LineNumber - 1].Insert(IndexInSubList, ByteToInsert);

如果要插入字節數組:

NestedList[LineNumber - 1].InsertRange(IndexInSubList, BytesToInsert);

您也可以通過索引器訪問嵌套列表集合。 然后使用Insert方法將數據插入所需的位置。

NestedList[LineNumber-1].Insert(IndexInSubList, ByteToInsert);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM