Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

c# 获取当前路径

作者:半盏流年   发布日期:2025-09-16   浏览:96

using System;
using System.IO;

class Program
{
    static void Main()
    {
        // 获取当前工作目录的路径
        string currentPath = Directory.GetCurrentDirectory();
        Console.WriteLine("当前工作目录: " + currentPath);

        // 获取包含可执行文件的目录的路径
        string exePath = AppDomain.CurrentDomain.BaseDirectory;
        Console.WriteLine("包含可执行文件的目录: " + exePath);
    }
}

解释说明:

  1. Directory.GetCurrentDirectory():获取当前工作目录的路径。当前工作目录是指应用程序启动时所在的目录,或者通过代码更改后的目录。
  2. AppDomain.CurrentDomain.BaseDirectory:获取包含可执行文件的目录路径。这个路径通常是应用程序的安装目录,不会随着当前工作目录的变化而变化。

这两个方法都可以用来获取当前路径,具体使用哪个取决于你的需求。

上一篇:c# byte转int

下一篇:c# byte 转string

大家都在看

c# 二进制

c# tcp client

c# type.gettype

c# sqlconnection

c# string.format 小数位数

.net和c#

c#获取系统时间

c#游戏开发

c#网络编程

c# rectangle

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站