please help, im trying to assign a random number variable which ive created called 'custID' in a Customer Class to an array list of customers called 'customerList' which is in the program.
Re: Assigning a random number to an array List c#?
Code:
Random rnd = new Random();
System.Collections.ArrayList rndID = new System.Collections.ArrayList();
int numsID = 20;
int minID = 1;
int maxID = 100;
for (int c = 1; c <= numsID; c++)
{
rndID.Add(rnd.Next(minID, maxID));
}
Re: Assigning a random number to an array List c#?
Originally Posted by ClassCoder
Code:
Random rnd = new Random();
System.Collections.ArrayList rndID = new System.Collections.ArrayList();
int numsID = 20;
int minID = 1;
int maxID = 100;
for (int c = 1; c <= numsID; c++)
{
rndID.Add(rnd.Next(minID, maxID));
}
I don't think you should be encouraging people to use ArrayList as it is deprecated. Generic List<> is strongly typed, has increased functionality and greater performance and memory usage. It's available on all versions of .NET since 2.0 I believe.
Re: Assigning a random number to an array List c#?
Originally Posted by Chris_F
I don't think you should be encouraging people to use ArrayList as it is deprecated. Generic List<> is strongly typed, has increased functionality and greater performance and memory usage. It's available on all versions of .NET since 2.0 I believe.
i agree with you .. i don't never use ArrayList in my applications .. i prefer using List<>,HashTable<,>,Dictionary<,>
Re: Assigning a random number to an array List c#?
thanks for the feedback - i've been told to use array list so i'm guessing i have to.
I have an arraylist called customerList and all i want to do is give each of the customers a Random number
so that when i execute the command to display all the customers in that array, it displays its ID alongside each individual customer.
Ive researched GUID's and they would have been ideal but they are too long and Random numbers are sure to be fine as its just a mini project with a few customers in the array.
Bookmarks