如何使用C#获取当前类文件的路径? [英] How Can I Get The Path Of Current Class File On That I Am Working Using C# ?

查看:102
本文介绍了如何使用C#获取当前类文件的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态地找出我正在编码的类文件的路径:意味着如果我在calss文件中工作:abc.cs,那么我想通过abc.cs中的代码找到abc.cs的路径c#。

解决方案

你不能:一旦项目被编译,就没有源代码的链接(调试版本除外,其中添加了额外的信息)调试器可以链接两个)。



你可以找到当前程序集正在执行的文件夹,如果这有帮助吗?

< pre lang =c#> string folder = Assembly.GetExecutingAssembly()。Location;


I want to find out dynamically the path of class file where i am coding: Means if i am working in calss file : abc.cs,then i want to find the path of abc.cs by code in abc.cs in c#.

解决方案

You can't: once the project is compiled, there is no link to the source code (except in debug builds, where extra info is added so the debugger can link the two).

You can find the folder the current assembly is executing from though, if that helps?

string folder = Assembly.GetExecutingAssembly().Location;


这篇关于如何使用C#获取当前类文件的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆