c# - 什么是 C# 中的 .class (在 Java 中使用)的等价物

标签 c# java class

在 Java 中:

TokenStream my_stream = analyser_exclude.tokenStream(fieldName, my_reader);
TermAttribute my_token = TermAttribute.getAttribute(TermAttribute.class);

在 VB.NET 中:

Dim my_stream As TokenStream = analyser_exclude.TokenStream("", my_reader)
Dim my_token As TermAttribute = DirectCast(my_stream.GetAttribute(GetType(TermAttribute)), TermAttribute)

我只是在 VB.NET 中更改了字段名,因为我不需要它。此代码适用于 VB.NET 但我不知道如何更改 C# 中的 DirectCast 和最后一行代码(在 Java 中)Termattribute.Class

在 C# 中: ???

请帮助我,我不知道如何在 C# 中更改这些行。

最佳答案

你正在寻找typeof:

TermAttribute my_token =
    (TermAttribute)my_stream.GetAttribute(typeof(TermAttribute));

关于c# - 什么是 C# 中的 .class (在 Java 中使用)的等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8200111/

相关文章:

java - 为什么递归函数会停止在随机数上?

c++ - 如何为其他类成员函数编写模板包装器方法?

C# 允许公开增加属性,但不允许显式设置

c# - 已成功注册 COM DLL - 一个可访问,一个不可访问

c# - 在运行时获取对象的成员

java - Java 中的泛型方法返回参数

java - Java 中的内联对象实例化和转换

c# - RestSharp 反序列化为 List<MyClass>

java - TreeModel 真的有我想的那么糟糕吗?

java - "Unwrap"在 Java 流(或并行流)中返回之前 Optional.empty 的可选