--------------------编程问答--------------------
用List(Of Tuple(Of 第一列类型, Of 第二列类型, Of 第三列类型, Of 第四列类型, Of 第五列类型))
--------------------编程问答--------------------
eg:
Dim list As List(Of Tuple(Of Integer, Of String,Of String, Of Double, Of Double)) = New List(Of Tuple(Of Integer, Of String,Of String, Of Double, Of Double))
list.Add(New Tuple(Of Integer, Of String,Of String, Of Double, Of Double)(1, "北京", "中国", -10.5, 21.5))
list.Add(New Tuple(Of Integer, Of String,Of String, Of Double, Of Double)(2, "上海", "中国", 8.1, 26.3))
list.Add(New Tuple(Of Integer, Of String,Of String, Of Double, Of Double)(3, "伦敦", "英国", 10.2, 25.5))
For Each item As Tuple(Of Integer, Of String,Of String, Of Double, Of Double) In list
MsgBox item.Item1 & " 最低气温:" & item.Item3 & " 最高气温:" item.Item4
Next
--------------------编程问答--------------------
请赐教 Of Tuple 是啥
Module Example
Public Sub Main()
' Organization of runningBacks 5-tuple:
' Component 1: Player name
' Component 2: Number of games played
' Component 3: Number of attempts (carries)
' Component 4: Number of yards gained
' Component 5: Number of touchdowns
Dim runningBacks() =
{ Tuple.Create("Payton, Walter", 190, 3838, 16726, 110),
Tuple.Create("Sanders, Barry", 153, 3062, 15269, 99),
Tuple.Create("Brown, Jim", 118, 2359, 12312, 106),
Tuple.Create("Dickerson, Eric", 144, 2996, 13259, 90),
Tuple.Create("Faulk, Marshall", 176, 2836, 12279, 100) }
' Calculate statistics.
' Organization of runningStats 5-tuple:
' Component 1: Player name
' Component 2: Number of attempts per game
' Component 3: Number of yards per game
' Component 4: Number of yards per attempt
' Component 5: Number of touchdowns per attempt
Dim runningStats() = ComputeStatistics(runningBacks)
' Display the result.
Console.WriteLine("{0,-16} {1,5} {2,6} {3,7} {4,7} {5,7} {6,7} {7,5} {8,7}",
"Name", "Games", "Att", "Att/Gm", "Yards", "Yds/Gm",
"Yds/Att", "TD", "TD/Att")
Console.WriteLine()
For ctr As Integer = 0 To runningBacks.Length - 1
Console.WriteLine("{0,-16} {1,5} {2,6:N0} {3,7:N1} {4,7:N0} {5,7:N1} {6,7:N2} {7,5} {8,7:N3}",
runningBacks(ctr).Item1, runningBacks(ctr).Item2, runningBacks(ctr).Item3,
runningStats(ctr).Item2, runningBacks(ctr).Item4, runningStats(ctr).Item3,
runningStats(ctr).Item4, runningBacks(ctr).Item5, runningStats(ctr).Item5)
Console.WriteLine()
Next
End Sub
Private Function ComputeStatistics(players() As Tuple(Of String, Integer, Integer, Integer, Integer)) _
As Tuple(Of String, Double, Double, Double, Double)()
Dim result As Tuple(Of String, Double, Double, Double, Double)
Dim list As New List(Of Tuple(Of String, Double, Double, Double, Double))()
For Each player In players
' Create result object containing player name and statistics.
result = Tuple.Create(player.Item1,
player.Item3/player.Item2, player.Item4/player.Item2,
player.Item4/player.Item3, player.Item5/player.Item3)
list.Add(result)
Next
Return list.ToArray()
End Function
End Module
' The example displays the following output:
' Name Games Att Att/Gm Yards Yds/Gm Yds/Att TD TD/Att
'
' Payton, Walter 190 3,838 20.2 16,726 88.0 4.36 110 0.029
'
' Sanders, Barry 153 3,062 20.0 15,269 99.8 4.99 99 0.032
'
' Brown, Jim 118 2,359 20.0 12,312 104.3 5.22 106 0.045
'
' Dickerson, Eric 144 2,996 20.8 13,259 92.1 4.43 90 0.030
'
' Faulk, Marshall 176 2,836 16.1 12,279 69.8 4.33 100 0.035
Structure SomeType
Public ID As Integer
Public Name As String
...
End Structure
Dim list As New List(Of SomeType)()
Dim st1 As New SomeType
st1.ID = 1
st1.Name = "a"
...
list.Add(st1)
--------------------编程问答--------------------
那好,给你一个简单例子:
List<List<string>> 字符组 = new List<List<string>>();
字符组.Add(new string[] { "啊啊啊啊", "啊啊啊啊啊啊啊啊" }.ToList());
怎么用自己去看了。
--------------------编程问答--------------------
个人觉得可以直接在表里面取出运算,不需要用到数组反而绕了。
这次《代码》模块升级后把我发表的资料丢了,不知怎么搞的,反而觉得不好用了?
--------------------编程问答--------------------
我直接运算1个多小时才跑了200多条数据,不知道是怎么回事!
我想试试取出数后的运算速度
--------------------编程问答--------------------
你这是VB.NET的代码,有没去试啊,根本无法定义
--------------------编程问答--------------------
数据表和数组一样都在内存中的不是?
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim list As List(Of Int16(,)) = New List(Of Int16(,))
list.Add(New Int16(,) {{1, 2}, {3, 4}})
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim list As List(Of Int16(,)) = New List(Of Int16(,))
list.Add(New Int16(,) {{1, 2}, {3, 4}})
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim list As List(Of Int16(,)) = New List(Of Int16(,))
Dim list1 As List(Of Int16(,,)) = New List(Of Int16(,,))
list1.Add(New Int16(,,) {{{1, 2, 3}, {3, 4, 5}}})
Dim datatable As DataTable = New DataTable()
datatable.Columns.Add("a1")
datatable.Columns.Add("a2")
datatable.Columns.Add("a3")
datatable.Columns.Add("a4")
datatable.Rows.Add()
datatable.Rows(0)(0) = "1"
datatable.Rows(0)(1) = "2"
datatable.Rows(0)(2) = "3"
datatable.Rows(0)(3) = "4"
list.Add({{datatable.Rows(0)(0), datatable.Rows(0)(1)}, {datatable.Rows(0)(2), datatable.Rows(0)(3)}})
Dim 总 As Int16 = list(0)(0, 0) * list(0)(0, 1) * list(0)(1, 0) * list(0)(1, 1)
End Sub