Dim array1() As String = {"0", "1", "-", "Z", "M", "9"}
Dim array2() As String = {"0", "1", "-", "Z", "M", "9", "1", "-", "Z", "M", "9", "1", "1", "1", "1", "1"}
Dim dt As New DataTable
dt.Columns.Add("BIN")
dt.Columns.Add("QTY")
For Each num In array1
Dim c As Integer = 0
dt.Rows.Add(num)
For Each num2 In array2.ToArray
If num = num2 Then
c = c + 1
End If
Next
dt.Rows(dt.Rows.Count - 1)(1) = c
Next
DataGridView1.DataSource = dt
Date :
2016-09-28 11:18:03
By :
jet_program
No. 4
Guest
สั้นฯ บรรทัดเดียวจบ
Code (VB.NET)
DataGridView1.DataSource = (From a In array2
Where array1.Contains(a)
Group a By Key = a Into Group
Select New With {Key .BIN = Key, Key .QTY = Group.Count}).ToList()
Dim หอยงาม = From a In array2.Intersect(array1)
Let ชั่วคราว = array2.Count(Function(v) a.Equals(v))
Select New With {.BIN = a, .QTY = ชั่วคราว}
For i As Integer = 0 To หอยงาม.Count - 1
MsgBox(หอยงาม(i).BIN & " นับได้ " & หอยงาม(i).QTY)
Next
DataGridView1.DataSource =หอยงาม.ToList()