【问题标题】:what is the equivalent of .class (used in Java) in C#C# 中 .class (在 Java 中使用)的等价物是什么
【发布时间】:2012-05-09 20:17:42
【问题描述】:

在 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 但我不知道如何使用(在 Java 中)Termattribute.Class 更改 C# 中的 DirectCast 和最后一行代码

在 C# 中: ???

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

【问题讨论】:

标签: c# java class


【解决方案1】:

你正在寻找typeof:

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

【讨论】:

    猜你喜欢
    • 2010-12-07
    • 2010-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-26
    • 2011-07-21
    相关资源
    最近更新 更多