问:“预期类型” [英] Q: "Type Expected"

查看:85
本文介绍了问:“预期类型”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在尝试使用我在表格中写过的课程。不幸的是,当我用
写下类似的东西:


Public x As New myClass


我得到编译时间错误:类型预期。实际上,波浪形是指波浪形。蓝色

行确实出现在myClass下面,所以我把它放了一半。但是,我写了


在表格中输入myClass


所以我认为它会起作用。


有人可以帮忙吗?我显然错过了一些明显的东西。


Geoff

Hi

I''m trying to use a class that I''ve written in a form. Unfortunately, when I
write something like:

Public x As New myClass

I get the compile time error: "Type Expected". Indeed, the "squiggly" blue
line does appear under myClass so I half expeced it. However, I had written

Imports myClass

in the form so I thought it would work.

Can anybody help? I''m obviously missing something obvious.

Geoff

推荐答案

Geoff,

MyClass是一个保留字,你不能命名一个类与保留的

字相同而没有转义字。它,在VB.NET中,您使用方括号[]来转义

关键字。


类似于:


公共班级[MyClass]

结束班级


公共x为新[MyClass]


希望这有助于

Jay


" Geoff Jones" <无******** @ email.com>在留言中写道

news:41 ********************** @ news.dial.pipex.com。 ..
Geoff,
"MyClass" is a reserved word, you cannot name a class the same as a reserved
word without "escaping" it, in VB.NET you use square brackets [] to "escape"
keywords.

Something like:

Public Class [MyClass]
End Class

Public x As New [MyClass]

Hope this helps
Jay

"Geoff Jones" <no********@email.com> wrote in message
news:41**********************@news.dial.pipex.com. ..


我正在尝试使用我在表单中编写的类。不幸的是,当我写下这样的内容时:

公共x作为新的myClass

我得到编译时错误:Type Expected。实际上,波浪形是指波浪形。蓝色
线确实出现在myClass下面,所以我把它放了一半。但是,我已经在表格中写了

进口myClass

所以我认为它会起作用。

有人可以帮忙吗?我显然错过了一些明显的东西。

Geoff
Hi

I''m trying to use a class that I''ve written in a form. Unfortunately, when
I write something like:

Public x As New myClass

I get the compile time error: "Type Expected". Indeed, the "squiggly" blue
line does appear under myClass so I half expeced it. However, I had
written

Imports myClass

in the form so I thought it would work.

Can anybody help? I''m obviously missing something obvious.

Geoff



啊,对不起周杰伦,但我误导了你。实际上我打电话给全班:


SmoothProgressBar


它仍然可以:(即我输入myClass以期简化

件事。抱歉。


Geoff


" Jay B. Harlow [MVP - Outlook]" < Ja ************ @ msn.com>在留言中写道

新闻:uV ************** @ TK2MSFTNGP14 .phx.gbl ...
Ah, sorry Jay, but I mislead you. Actually I''ve called the class:

SmoothProgressBar

and it still does it :( i.e. I typed myClass in the hope of simplifying
things. Sorry.

Geoff

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uV**************@TK2MSFTNGP14.phx.gbl...
Geoff,
MyClass是一个保留字,你不能将一个类命名为
保留字,而不是转义。它,在VB.NET中你使用方括号[]
来转义关键字。

公共类[MyClass]
结束课

公共x作为新[MyClass]

希望这有帮助
杰伊

杰夫琼斯< no ********@email.com>在留言中写道
新闻:41 ********************** @ news.dial。 pipex.com .. ..
Geoff,
"MyClass" is a reserved word, you cannot name a class the same as a
reserved word without "escaping" it, in VB.NET you use square brackets []
to "escape" keywords.

Something like:

Public Class [MyClass]
End Class

Public x As New [MyClass]

Hope this helps
Jay

"Geoff Jones" <no********@email.com> wrote in message
news:41**********************@news.dial.pipex.com. ..


我正在尝试o使用我在表格中写的课程。不幸的是,当我写下这样的东西时:

公共x作为新的myClass

我得到编译时错误:Type Expected。实际上,波浪线的蓝线确实出现在myClass下面,所以我把它放了一半。但是,我已经在表格中写了

进口myClass

所以我认为它会起作用。

有人可以帮忙吗?我显然错过了一些明显的东西。

Geoff
Hi

I''m trying to use a class that I''ve written in a form. Unfortunately,
when I write something like:

Public x As New myClass

I get the compile time error: "Type Expected". Indeed, the "squiggly"
blue line does appear under myClass so I half expeced it. However, I had
written

Imports myClass

in the form so I thought it would work.

Can anybody help? I''m obviously missing something obvious.

Geoff




" Geoff Jones" <无******** @ email.com> schrieb:
"Geoff Jones" <no********@email.com> schrieb:
我正在尝试使用我在表单中编写的类。不幸的是,当我写下这样的内容时:

公共x作为新的myClass

我得到编译时错误:Type Expected。实际上,波浪形是指波浪形。蓝色
线确实出现在myClass下面,所以我把它放了一半。但是,我写了


''MyClass''是VB.NET的关键字,因此不能用作类名

除非你把它放在方括号内:

导入myClass
I''m trying to use a class that I''ve written in a form. Unfortunately, when
I write something like:

Public x As New myClass

I get the compile time error: "Type Expected". Indeed, the "squiggly" blue
line does appear under myClass so I half expeced it. However, I had
written
''MyClass'' is a keyword of VB.NET and thus cannot be used as a class name
unless you put it into square brackets:
Imports myClass




你不需要导入这个类。相反,导入类

所属的命名空间。我建议不要命名一个班级''MyClass''并使用更多

有意义的班级名称。


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< URL:http:// dotnet。 mvps.org/dotnet/faqs/>



You don''t need to import the class. Instead, import the namespace the class
is part of. I suggest not to name a class ''MyClass'' and use a more
meaningful class name instead.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


这篇关于问:“预期类型”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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