C# - Environment.GetLogicalDrives() Method with Example

In this tutorial, we will learn about the C# Environment.GetLogicalDrives() method with its definition, usage, syntax, and example. By Nidhi Last updated : March 30, 2023

Environment.GetLogicalDrives() Method

The Environment.GetLogicalDrives() method is used to get the logical drives of the computer system.

Syntax

string[] Environment.GetLogicalDrives();

Parameter(s)

This method does not accept any parameter.

Return Value

This method returns an array of strings that contains the name of logical drives of the computer system.

C# Example of Environment.GetLogicalDrives() Method

The source code to get the logical drives of computer system using Environment class is given below. The given program is compiled and executed successfully.

using System;

class Sample
{
    //Entry point of Program
    static public void Main()
    {
        string[] logicalDrives;

        logicalDrives = Environment.GetLogicalDrives();

        Console.WriteLine("Logical Drives of computer:");
        foreach (string drive in logicalDrives)
        {
            Console.WriteLine("\t" + drive);
        }
    }
}

Output

Logical Drives of computer:
        C:\
        D:\
        E:\
        F:\
        H:\
Press any key to continue . . .

C# Environment Class Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.