Code
  • 首页
  • cpu-architecture
  • performance
  • c++
  • branch-prediction
  • java
2023-06-20 06:00:05

c#获取自己的类名

c#reflection

如果我有一个名为MyProgram的类,是否有一种方法检索“MyProgram”作为字符串?


当前回答

在c# 6.0中,你可以使用操作符的名称:

nameof(MyProgram)
2014-08-20 22:02:22

其他回答

这个可以省略。所有你需要得到当前类名的是:

GetType().Name
2017-08-08 13:25:56

试试这个:

this.GetType().Name
2010-01-21 21:31:21

我还想把这个吐出来。我认为@micahtan的发帖方式更可取。

typeof(MyProgram).Name
2010-01-21 21:32:59

获取Asp.net的当前类名

string CurrentClass = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name.ToString();
2017-10-07 03:10:34

这可以用于泛型类

typeof (T)。的名字

2021-04-25 21:43:45

推荐文章

  • 实体框架核心:在上一个操作完成之前,在此上下文中开始的第二个操作
  • 如何为构造函数定制Visual Studio的私有字段生成快捷方式?
  • 如何使用JSON确保字符串是有效的JSON。网
  • AppSettings从.config文件中获取值
  • 通过HttpClient向REST API发布一个空体
  • 如何检查IEnumerable是否为空或空?
  • 自动化invokerrequired代码模式
  • 在c#代码中设置WPF文本框的背景颜色
  • 在c#中,什么是单子?
  • c#和Java中的泛型有什么不同?和模板在c++ ?
  • c#线程安全快速(est)计数器
  • 如何将此foreach代码转换为Parallel.ForEach?
  • 如何分裂()一个分隔字符串到一个列表<字符串>
  • 如何转换列表<字符串>列表<int>?
  • c#对象列表,我如何得到一个属性的和

aliyun

最新文章

  • 如何删除默认的导航栏空间在SwiftUI导航视图
  • 我可以列出所有的标准Go包吗?
  • 证书验证失败:无法获得本地颁发者证书
  • 警告:API ' variable . getjavacompile()'已过时,已被' variable . getjavacompileprovider()'取代
  • 打开同一目录两次
  • 实体框架核心:在上一个操作完成之前,在此上下文中开始的第二个操作
  • NullInjectorError: AngularFirestore没有提供程序
  • 如何为构造函数定制Visual Studio的私有字段生成快捷方式?
  • 从元组/数组值派生联合类型
  • 如何在Angular2中截断文本?
  • 安装tzdata非交互式
  • ionic 2 - Error在Android Studio中找不到Gradle的安装版本
  • 如何查看所有地区所有正在运行的Amazon EC2实例?
  • 当使用pip3安装包时,“Python中的ssl模块不可用”
  • 安装APK时出现错误

标签

cpu-architectureperformancec++branch-predictionjavaundogit-commitgitversion-controlgit-remotegit-pushgit-branchgit-pullgit-fetchpythongeneratoriteratorjsonmime-typescontent-typearraysjavascriptgit-addcode-formattingcstandards-complianceoperatorscommentsdynamic-memory-allocationstackmemory-managementheap-memorylanguage-agnosticoverwritebackground-colorbrowserhtmldomjqueryvisibilityuse-strictsyntaxjslintremote-branchgit-checkoutpython-moduleidiomsprogram-entry-pointnamespacesbranch
2025 code 京ICP备15047053号-1