什么是C#中的.class(在Java中使用)的等价物 [英] what is the equivalent of .class (used in Java) in C#

查看:179
本文介绍了什么是C#中的.class(在Java中使用)的等价物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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

I just changed the fieldname in VB.NET because I didn't need it. This code works in VB.NET but I don't know how to change the DirectCast in C# and the last line of code with (in Java) Termattribute.Class

在C#中:
???

In C# : ???

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

Help me please I don't know how to change those lines in C#.

推荐答案

您正在寻找 typeof

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

这篇关于什么是C#中的.class(在Java中使用)的等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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