Sorting Combobox Items Alphabetically

To sort a collection of items inside a combobox alphabetically, one way to do it would be to use the SortDescription class. For this, first you need to add the System.ComponentModel namespace. Then initialize a new SortDescription class in which you can tell by what and how to arrange the list. And finally simply add the class to the combobox you wish to be arranged. In case you want to arrange a simple combobox (only one thing to arrange it by) use the "Content" string when initializing the class as shown in the example bellow:

SortDescription sd = new SortDescription("Content", ListSortDirection.Ascending);
comboBox1.Items.SortDescriptions.Add(sd);

Get The Total Size of Multiple HDD

The following code will show you how it can be retrieved the total size of multiple HDDs installed on your system. Using the same method you can do this for available free space. I've also converted bytes to GB as the value is retrieved in bytes. For this you can use the Size property from the Win32_DiskDrive class:

private static String getHDDsize()
        {
            Double sum = 0;

            ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * From Win32_DiskDrive");

            foreach (ManagementObject item in mos.Get())
            {
                double HDD_size = Convert.ToDouble(item["Size"]);
                sum += HDD_size;
            }

            return Convert.ToString(Math.Round(sum / 1073741824, 2)) + " GB";
        }

Retrieving the System's Total Physical Memory

Recently I was creating an app in which I needed to display the total physical memory inside a label. At first I was tempted to retrieve the memory using the Capacity property from Win32_PhysicalMemory, but it seems that this property retrieves the memory from each module. Although it does the job, I found out that is more efficient to retrieve the total physical memory using the TotalPhysicalMemory property from the Win32_ComputerSystem WMI class.

The following code shows you how to retrieve it using a foreach loop. Note that this property retrieves the memory in bytes and I've did some calculations to display it in GB. Then, this method can be used to display the memory amount inside a label... or whatever.

private static String getRAMsize()
        {
            ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
            ManagementObjectCollection moc = mc.GetInstances();
            foreach (ManagementObject item in moc)
            {
                return Convert.ToString(Math.Round(Convert.ToDouble(item.Properties["TotalPhysicalMemory"].Value) / 1073741824, 2)) + " GB";
            }

            return "RAMsize";
        }