【发布时间】:2015-11-18 05:16:24
【问题描述】:
我是 VB.Net 的新手,因为我来自 PHP 开发。请问VB.NET中是否有array_count_values之类的函数。
我需要计算我的 Excel 中所有出现的项目。
【问题讨论】:
-
我还没有这个代码。我所拥有的只是excel中所有数据的数组。我正在做 PHP 但我需要在 VB.Net 上传输它
标签: vb.net
我是 VB.Net 的新手,因为我来自 PHP 开发。请问VB.NET中是否有array_count_values之类的函数。
我需要计算我的 Excel 中所有出现的项目。
【问题讨论】:
标签: vb.net
使用 LINQ
Dim myarray As String() = {"HP", "IBM", "HP", "HP", "MICROSOFT"}
Dim occur = myarray.GroupBy(Function(f) f).Select( _
Function(f1) New With {.Item = f1.Key, .Count = f1.Count()})
Dim out As String
For Each itm In occur
out = out & itm.ToString & vbCrLf
Next
MsgBox(out)
{Item = MICROSOFT, Count = 1}
{Item = HP, Count = 3}
{Item = IBM, Count = 1}
【讨论】:
您可能正在寻找数组对象的Array.Length Property。
获取Array所有维度的元素总数。
示例来自 MSDN 本身:
using System;
public class Example
{
public static void Main()
{
// Declare a single-dimensional string array
String[] array1d = { "zero", "one", "two", "three" };
ShowArrayInfo(array1d);
}
private static void ShowArrayInfo(Array arr)
{
Console.WriteLine("Length of Array: {0,3}", arr.Length);
Console.WriteLine("Number of Dimensions: {0,3}", arr.Rank)
Console.WriteLine();
}
}
输出
// The example displays the following output:
// Length of Array: 4
// Number of Dimensions: 1
【讨论】:
Console.WriteLine("Length of Array: {0,3}", arr.Length);
试试这个:
Dim brands() As String = New String() {"HP", "IBM", "HP", "HP", "MICROSOFT"}
Dim result = From brand In brands
Group brand By brand Into brandgroup = Group
For Each e In result
Console.WriteLine("brand : {0} count : {1}", e.brand, e.brandgroup.Count)
Next
【讨论】: