DirectCast无效 [英] DirectCast invalid

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

问题描述

您好


我有以下代码:


Public Groupes作为新的Hashtable


Dim Entry As DictionaryEntry

每个Groupes条目

Dim Gr As Groupe = DirectCast(Entry.Value,Groupe)

=== >这条线给我一个错误的DIRECTCAST是没有用的

下一个


有人能告诉我我做错了吗?

谢谢


伯纳德


PS:这是我的班级Groupe


朋友级Groupe


私人mNom为字符串

私人mNum为短

私人mCat为Quotes.CatABC


''Stockage pourlenuméroIDdedébogage。

私人mlDebugID作为整数

公共财产Nom()作为字符串

获取

Nom = mNom

结束获取

设置(ByVal值为字符串)

mNom = Value

结束套件

结束物业

公共财产数量()为短期

获取

Num = mNum

结束获取

套装(ByVal价值为空头)

mNum =价值

结束设置

结束物业

公共物业Cat()As Quotes.CatABC

获取

Cat = mCat

结束Ge t

套装(ByVal Value As Quotes.CatABC)

mCat =价值

结束套件

结束财产


Public Sub New()

MyBase.New()

End Sub

受保护的覆盖子完成()

MyBase.Finalize()

结束子

结束班

解决方案




Dim Entry As DictionaryEntry

每个Groupes条目

Dim Gr As Groupe = CType(Entry.Value,Groupe)

下一页


Ken

----------- ------

"BernardBourée" <是***** @ bouree.net>在消息中写道

新闻:e6 ************* @ TK2MSFTNGP12.phx.gbl ...

你好


我有以下代码:


Public Groupes As New Hashtable


Dim Entry As DictionaryEntry
每团Groupes


Dim Gr As Groupe = DirectCast(Entry.Value,Groupe)

===>这条线给我一个错误的DIRECTCAST是没有用的

下一个


有人能告诉我我做错了吗?

谢谢


伯纳德


PS:这是我的班级Groupe


朋友级Groupe


私人mNom为字符串

私人mNum为短

私人mCat为Quotes.CatABC


''Stockage pourlenuméroIDdedébogage。

私人mlDebugID作为整数

公共财产Nom()作为字符串

获取

Nom = mNom

结束获取

设置(ByVal值为字符串)

mNom = Value

结束套件

结束物业

公共财产数量()为短期

获取

Num = mNum

结束获取

套装(ByVal价值为空头)

mNum =价值

结束设置

结束物业

公共物业Cat()As Quotes.CatABC

获取

Cat = mCat

结束Ge t

套装(ByVal Value As Quotes.CatABC)

mCat =价值

结束套件

结束财产


Public Sub New()

MyBase.New()

End Sub

受保护的覆盖子结束()

MyBase.Finalize()

结束子

结束类


您是否在DirectCast行中为类指定了完整的命名空间?


例如Dim Gr As Groupe = DirectCast(Entry.Value,MyNamespace.Groupe)


Bernard,


为什么选择你想投这个吗?你的程序,当它完成时,没有完成任何事情,但是即使哈希表有数据,我认为不需要演员是
并且会有仍然没有做任何事情。


你有一个空的哈希表,试图在程序实例化对象组中将默认值从

an设置为其值。当达到下一个对象时,此实例

对象将直接超出范围。但是,你没有
没有默认值。


因此,问题不是演员而是你在做什么。


首先尝试思考你想要实现的目标,如果不成功,那么我们可以帮助你告诉如何实现这一目标。




虽然这可能不是你想要的答案,但我希望这会有所帮助。


Cor



Hello

I have the following code:

Public Groupes As New Hashtable

Dim Entry As DictionaryEntry
For Each Entry In Groupes
Dim Gr As Groupe = DirectCast(Entry.Value, Groupe)
===> THIS LINE GIVE ME AN ERROR DIRECTCAST IS NOT VALID
Next

Can someone tell me what I''m doing wrong ?

Thanks

Bernard

PS: Here is my class Groupe

Friend Class Groupe

Private mNom As String
Private mNum As Short
Private mCat As Quotes.CatABC

'' Stockage pour le numéro ID de débogage.
Private mlDebugID As Integer
Public Property Nom() As String
Get
Nom = mNom
End Get
Set(ByVal Value As String)
mNom = Value
End Set
End Property
Public Property Num() As Short
Get
Num = mNum
End Get
Set(ByVal Value As Short)
mNum = Value
End Set
End Property
Public Property Cat() As Quotes.CatABC
Get
Cat = mCat
End Get
Set(ByVal Value As Quotes.CatABC)
mCat = Value
End Set
End Property

Public Sub New()
MyBase.New()
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class

解决方案

Hi,

Dim Entry As DictionaryEntry
For Each Entry In Groupes
Dim Gr As Groupe = CType(Entry.Value, Groupe)
Next

Ken
-----------------
"Bernard Bourée" <be*****@bouree.net> wrote in message
news:e6*************@TK2MSFTNGP12.phx.gbl...
Hello

I have the following code:

Public Groupes As New Hashtable

Dim Entry As DictionaryEntry
For Each Entry In Groupes
Dim Gr As Groupe = DirectCast(Entry.Value, Groupe)
===> THIS LINE GIVE ME AN ERROR DIRECTCAST IS NOT VALID
Next

Can someone tell me what I''m doing wrong ?

Thanks

Bernard

PS: Here is my class Groupe

Friend Class Groupe

Private mNom As String
Private mNum As Short
Private mCat As Quotes.CatABC

'' Stockage pour le numéro ID de débogage.
Private mlDebugID As Integer
Public Property Nom() As String
Get
Nom = mNom
End Get
Set(ByVal Value As String)
mNom = Value
End Set
End Property
Public Property Num() As Short
Get
Num = mNum
End Get
Set(ByVal Value As Short)
mNum = Value
End Set
End Property
Public Property Cat() As Quotes.CatABC
Get
Cat = mCat
End Get
Set(ByVal Value As Quotes.CatABC)
mCat = Value
End Set
End Property

Public Sub New()
MyBase.New()
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class


Did you specify the full namespace to the class in the DirectCast line?

e.g. Dim Gr As Groupe = DirectCast(Entry.Value, MyNamespace.Groupe)


Bernard,

Why do you want to cast this? Your procedure, when it is complete, there is
nothing done, however even when the hashtable would have data, the cast is
in my opinion not needed and there will be still nothing done.

You have an empty hashtable from which you try to set the default value from
an in the procedure instanced object groupe, to its value. This instanced
object will go directly out of scope when the next is reached. However, you
don''t have a default value.

Therefore the problem is not the cast however what you are doing.

First try to think what you want to achieve and if that does not succeed,
than we will when we can help you with telling how to achieve that.

Although it is maybe not the answer you expected, do I hope this helps.

Cor



这篇关于DirectCast无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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