I am developing a console based banking application in C#! i have to get details of account dynamically..I am confused what to use whether array of objects or List. As i am beginner i dont know much about both . Could anyone help me what to use? i should save account details of savings and overdraft account separately . I should retrieve data based on account number to perform withdraw and deposit also. So kindly help me in this.
3 Answers
Unless you know the different, use a List<T>
for everything. List
s implement what is called a dynamic array behind the scenes, which is a regular array who's size is increased on demand.
Example usage:
// Create an integer array
List<int> list = new List<int>();
// Add 5 numbers
list.Add(1);
list.Add(5);
list.Add(3);
list.Add(4);
list.Add(2);
// Get value at index 0 and write to console
Console.WriteLine(list[0]); // 1
Here is some more advanced usage using LINQ which was introduced in .NET 3.5.
// Get all values less than 4 and put into an 'IEnumerable'
var lessThanFour = list.Where(e => e < 4);
// Write all values less than 4 to the console
foreach (var val in lessThanFour)
{
Console.WriteLine(val);
}

- 47,944
- 19
- 150
- 166
-
any example on how to store it and retrieve from list ? – Chetan Goenka Mar 09 '13 at 16:23
-
1This should be your accepted answer. I will caution you though that interfacing with a bank can be a serious matter. Not understanding the difference between and Array and a List
is a cause for concern. – Chase Florell Mar 09 '13 at 16:29
Okay. I'm going to help you design your data structures, but I doubt anyone is going to directly give you the code.
Account Class
It sounds like, to me, you want a class Account. An Account
might have certain values:
- An account holder.
- An account number.
- A balance.
This should give you some idea of the fields inside the Account
class.
In terms of the class' functionality, it looks like you want to be able to:
- GET the account Number.
- GET the account balance
- GET the account holder.
- SET the new account balance
You also mentioned you want different types of accounts. Read up a little on inheritance, and that should spark your creativity.
Storage Mechanism
If it were me, I would store it in a List. A list is a dynamic object, meaning you can have as many account objects stored in it as you want. To use a list, you should read the documentation provided.
Hopefully this will help you solve your problem. :)

- 26,815
- 5
- 55
- 89
You're not really saying exactly what you need to do with your collection, but overall, a List<someObject>
will be more flexable, but will cause more performance hits.
If you're using someObject[]
, it could potentially be more performant, but at the expense of "features".
Basically, rock a List<someObject>
and have fun.

- 46,378
- 57
- 186
- 376