第1个回答 2010-04-14
Dim x%, y%, z%, C As Boolean
'例如数组名称为SN
z = 1
For x = 1 To UBound(SN) - 1
C = False
For y = x + 1 To UBound(SN)
If SN(x) = SN(y) Then C = True: Exit For
Next
If Not C Then z = z + 1
Next
MsgBox "共有" & z & "个不同数组!"
第2个回答 2010-04-14
Dim g(5) As Integer
g(0) = 123456
g(1) = 124255
g(2) = 123456
g(3) = 326231
g(4) = 512214
g(5) = 123456
For i = 0 To Ubound(g)
For j = 0 To Ubound(g)
If g(i) = g(j) And i <> j And g(i) <> -1 Then
g(i) = -1
End If
Next j
Next i
Dim c As Integer
For i = 0 To Ubound(g)
If g(i) <> -1 Then
c = c + 1
End If
Next i
Msgbox "不同的数组个数为" & c & "个"
第3个回答 2010-04-14
C#的语法。
int [] a = new int []{123456,
124255,
123456,
326231,
512214,
123456};
List<int> lst = new List<int>();
foreach(int i in a)
{
if (!lst.Contain(i))
{
lst.Add(i);
}
}
Console.WriteLine("不同的数量有{0}个.", lst.Count);