C#/Xamarin 相当于 class.getSimpleName()

C#/Xamarin equivalent of class.getSimpleName()

我正在手动将 Android Studio 项目移植到 Visual Studio / Xamarin.我有这个 Java 代码:

throw new IllegalStateException(MyClass.class.getSimpleName() + " is not initialized.");

我正在尝试找到 .getSimpleName() 的等价物。

我在网上找到了一些可以尝试的东西:

throw new IllegalStateException(MyClass.ShortClassName +" is not initialized.);
throw new IllegalStateException(nameOf(MyClass) +  " is not initialized.");

但是这些都不编译。
你能告诉我等价物是什么吗?

你可以试试 typeof(myclass).Name。为了完整起见,如果您需要带命名空间的扩展名称,请使用:typeof(myclass).FullName

可能要查找的是来自 Type class. The Name property will give you the "simple" name of the class, where FullName 的一些信息,这些信息为您提供了 class 的完全限定名称。