What is the most efficient way to list drives in a ComboBox using C #?

I am creating a program that allows the user to select a drive letter from a combo box. I discuss how to populate a field using a list or array. What is the best and most effective way to do this?

+4
source share
4 answers

To fill it, there is no distinguishable difference between a list and an array.

Personally, I would use a list, since it is usually easier to use (it can add / remove elements without a fixed length, etc.), and using generics there is type safety similar to an array. I know that it makes no sense to associate it with a list, but it makes it easier to get this point.

+5
source

Effective will never be a problem here, with a maximum of 26 letters.

The combobox is going to be copied to the internal list, as the source you can use everything that is most convenient.

+3
source

I would do the following:

ListBox.Items.AddRange(Environment.GetLogicalDrives()); 

For the number of disks that you will have little to change, how do you do it.

+2
source

Pretty simple:

 ComboBox cb = new ComboBox(); string[] drives = Environment.GetLogicalDrives(); foreach (string drive in drives) { cb.Items.add(drive); } 
+1
source

All Articles