【发布时间】:2014-11-23 22:53:50
【问题描述】:
如何使用 .netmf(VB 或 C#)多次重复数组?
您将在下面找到我用来构建 Byte() 的函数。它所做的只是获取一个 8 字符的字符串(例如 10101000),并将每个字符的相位替换为 252 和 0 的 128 并将其转储到字节数组中。例如。
Dim bytes() as array = {252,128,252,128,252,128,128,128}
^^^^ 将是等价的。^^^^
假设我使用我的函数并传递一个字符串 10101011
Dim N as integer = 3
Dim Teststring as string = "10101011"
Dim testbyte() as byte = Allbytes2send(Teststring , N)
Testbyte() 现在应该用相位字符串填充 3 次
For each b in Testbyte
Debug.Print(b.tostring)
Next
'{252,128,252,128,252,128,252,252,252,128,252,128,252,128,252,252,252,128,252,128,252,128,252,252}
功能
Shared Function Allbytes2send(ByVal color As String) As Byte()
Dim bitcolor As String() = New String(color.Length - 1) {}
Dim b2sa As Byte() = New Byte(bitcolor.Length - 1) {}
For i As Integer = 0 To color.Length - 1
bitcolor(i) = color(i).ToString()
Next
For i As Integer = 0 To bitcolor.Length - 1
Dim data As String = bitcolor(i)
Select Case data
Case "0"
bitcolor(i) = "128"
Case "1"
bitcolor(i) = "252"
End Select
Next
For i As Integer = 0 To bitcolor.Length - 1
b2sa(i) = Byte.Parse(bitcolor(i))
Next
Return b2sa
End Function
【问题讨论】:
标签: c# arrays vb.net .net-micro-framework