arraylist length problem

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

arralistLength namespace
{
  class Program
  {
    static void the Main (String [] args)
  {
Time / * number of each set of elements actually contained (count) than the number of elements can contain (capcity) of
// set to We will seek to open up more space in memory twice, to ensure that the length of the collection has been enough
    ArrayList List = new new ArrayList ();
    list.add (1);
    Console.WriteLine (list.Count);
    Console.WriteLine (List. Capacity);
    the Console.ReadKey ();
the number of // elements actually contained in the COUNT
// capcity element may be included in the number of * /

// create a collection, which add some numbers, and averaging the maximum median, minimum
    the ArrayList List = new new the ArrayList ();
    list.AddRange (new new int [] {1,2,3,4,5,6,7,8,9});
    int SUM = 0;
    int max = ( int) List [0];
    for (int I = 0; I <list.Count; I ++)
    {
      sum += (int)list[i];
      if ((int)list[i] > max)
    {
      max = (int)list[i];
    }
  }
    Console.WriteLine(sum);
    Console.WriteLine(max);
    Console.WriteLine(sum / list.Count);
    Console.ReadKey();


// write a set of length 10, which requires 10 stored random numbers (0-9), but does not require all digital repeating
    the ArrayList = new new List1 the ArrayList ();
    the Random R & lt new new = the Random ();
    for ( 0 = I int; I <10; I ++)
    {
      int r.Next rnumber = (0, 10);
      IF (list.Contains (rnumber!))
        {
          list.add (rnumber);
        }
      the else
    {
      I -; / / Once this cycle random number generation will not count
    }

   }
    for (int i = 0; i < list.Count; i++)
    {
      Console.WriteLine(list[i]);
    }
    Console.ReadKey();

          }

      }
}

Guess you like

Origin www.cnblogs.com/lz-huihui/p/11306432.html