Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I need to create a list, that will capture values as the session develops. Each day there will be a different number of values I need to store. I am mainly wanting to do this so that I can print the values out at the end of each session in a specific format.
I really have no idea what a list is, how it works, or anything like that, so I am needing a pretty basic, SIMPLE explanation or example of such a method in practice.
Any help would be appreciated.
Can you help answer these questions from other members on NexusFi?
You can use an ArrayList object. It is basically an array with a variable size, which allows you to add elements of various data types.
Step 1: create the array list:
You have now an empty ArrayList.
Step 2: Add elements to your array list:
It is important to specify the data type that you add.
Step 3: Retrieve the stored value.
This will retrieve the 6th value that you have added.
Tip
When adding or retrieving a value, you need to specify the data type which is stored in the array list. Without adding (double) in front of the array element, neither adding nor retrieving a value will work.
Of course you can use other data types, for example you can add (string) values.
Going off what Fat Tails said, there is also the List<T> type. It allows you to give a type to your List so if you only want doubles you can do List<double> myDoubleList = new List<double>()
I like the list if you are planning on looping through and want a strong statically typed object. If you need to access it by index then ArrayList is probably better.
Going off what Fat Tails said, there is also the List<T> type. It allows you to give a type to your List so if you only want doubles you can do List<double> myDoubleList = new List<double>()
I like the list if you are planning on looping through and want a strong statically typed object. If you need to access it by index then ArrayList is probably better.
You can access a List<T> by index.
List<double> will have a better performance than ArrayList because doubles won't be casted to objects when inserting, and objects won't be casted to doubles when accessing. List<double> will also be safer because you will always be sure your list only contains valid doubles, not random objects.
So IMO you'd better use List<double>. ArrayLists are legacy objects used before generic collections appeared in .NET 2.0
List<int> list = new List<int>();
list.Add(2);
list.Add(3);
list.Add(7);
foreach (int prime in list) // Loop through List with foreach
{
Console.WriteLine(prime);
}
List<double> will have a better performance than ArrayList because doubles won't be casted to objects when inserting, and objects won't be casted to doubles when accessing. List<double> will also be safer because you will always be sure your list only contains valid doubles, not random objects.
So IMO you'd better use List<double>. ArrayLists are legacy objects used before generic collections appeared in .NET 2.0
List<int> list = new List<int>();
list.Add(2);
list.Add(3);
list.Add(7);
foreach (int prime in list) // Loop through List with foreach
{
Console.WriteLine(prime);
}