日期:2014-05-18  浏览次数:20872 次

以下是VBA代码,谁能帮我改为C#
以下是VBA代码,谁能帮我改为C# 
function 35选7()
  Randomize (Time)
  Dim a(8) As Long
  Dim i As Integer, j As Integer

  For i = 1 To 7
  a(i) = Int(Rnd() * 35 + 1)
  For j = 0 To i - 1
  If a(i) = a(j) Then
  i = i - 1
  Exit For
  End If
  Next
  Next
end function



------解决方案--------------------
35选7??
------解决方案--------------------
int[] a = new int[7];
Random myR = new Random(unchecked((int)DateTime.Now.Ticks));


for (int i=0;i<7;i++)
{
a[i] = myR.Next(1,35);

for (int j=0;j<i-1; j++)
{
if(a[i] == a[j])
{
i-=1;
break;
}
}
}
------解决方案--------------------
C# code


        public string _35选7()
        {
            //Randomize (Time) 
            long[] a = new long[8];//Dim a(8)    As Long 
            int i, j;  //Dim i As Integer, j As Integer 
            for (int i = 0; i < 7; i++)
            {
                a[i] = (int)(Rnd() * 35 + 1);
                for (int j = 0; j < i; j++)
                {
                    if (a(i) == a(j))
                    {
                        i = i - 1;
                        continue;
                    }                 
                }                
            }
        }

------解决方案--------------------
这是要算彩票?
------解决方案--------------------

 void test() 
{
Randomize (Time); 
long[] a =new long[8];
int i,j;
for (i=1;i<=7;i++)
{
a[i] = Int(Rnd() * 35 + 1);
for (j = 0; i <= i - 1; )
{
if (a[i] == a[j])
{
i = i - 1;
}
}
}
}
}




}
------解决方案--------------------
不得不承认,我老了。。。