在不知道演员的情况下进行类型转换 [英] Typecasting without knowing the cast

查看:113
本文介绍了在不知道演员的情况下进行类型转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个数据行变量,可以用于我的应用程序中的许多表格中的任何一个。如何在运行时键入变量以更正类型?我知道

我可以使用MyRow.ToString获取类型描述但不知道怎么用
使用它来强制转换MyRow变量。我需要这个写一个通用的SUB,

可以处理任何表类型的行。


谢谢


问候

Hi

I have a data row variable which could be for any of a number of tables in
my apps. How can I type cast the variable to correct type at runtime? I know
I can get the type description using MyRow.ToString but don''t know how to
use this to typecast MyRow variable. I need this to write a generic SUB that
can deal with rows of any table type.

Thanks

Regards

推荐答案

" John" < in ** @ nospam.infovis.co.ukschrieb
"John" <in**@nospam.infovis.co.ukschrieb




我有一个数据行变量,可以适用于我的应用中的任何一个

表。如何在运行时键入变量以更正类型

?我知道我可以使用

MyRow.ToString获取类型描述但不知道如何使用它来对类型MyRow

变量进行类型转换。我需要这个来编写一个通用的SUB,可以处理任何表类型的行


Hi

I have a data row variable which could be for any of a number of
tables in my apps. How can I type cast the variable to correct type
at runtime? I know I can get the type description using
MyRow.ToString but don''t know how to use this to typecast MyRow
variable. I need this to write a generic SUB that can deal with rows
of any table type.



也许您正在寻找:


如果typeof行是CustomerRow那么

directcast (行,CustomerRow)。会员''任何类型特定的成员

其他类型的行是contractRow然后


''...


结束如果


在设计时不知道目的地类型的类型转换确实

没有意义。 Casting可以编写特定于某种类型的代码。如果您不知道目的地类型,那么

无法写出特定类型的代码。

Armin

Maybe you are looking for this:

if typeof row is CustomerRow then
directcast(row, CustomerRow).Member ''any type specific member
elseif typeof row is contractRow then

''...

end if

Type casting without knowing the destination type at design time does
not make sense. Casting is there to be able to write code that is
specific to a certain type. If you don''t know the destination type, you
can not write type specific code.
Armin


4月28日晚上10点31分,John < i ... @nospam.infovis.co.ukwrote:
On Apr 28, 10:31 pm, "John" <i...@nospam.infovis.co.ukwrote:




我有一个数据行变量这可能适用于我的应用程序中的任何一个表格。如何在运行时键入变量以更正类型?我知道

我可以使用MyRow.ToString获取类型描述但不知道怎么用
使用它来强制转换MyRow变量。我需要这个写一个通用的SUB,

可以处理任何表类型的行。


谢谢


问候
Hi

I have a data row variable which could be for any of a number of tables in
my apps. How can I type cast the variable to correct type at runtime? I know
I can get the type description using MyRow.ToString but don''t know how to
use this to typecast MyRow variable. I need this to write a generic SUB that
can deal with rows of any table type.

Thanks

Regards



John,

要知道对象的类型,请使用GetType函数来确定。然后

也许你会有类型铸造的改变。


希望这会有所帮助,


Onur

John,
To know the type of object, use GetType function to determine. Then
maybe you''ll have a change for type casting.

Hope this helps,

Onur


2008-04-28,John< in ** @ nospam.infovis.co.ukwrote:
On 2008-04-28, John <in**@nospam.infovis.co.ukwrote:

您好


我有一个数据行变量,可以用于我的应用程序中的任何一个表格。如何在运行时键入变量以更正类型?我知道

我可以使用MyRow.ToString获取类型描述但不知道怎么用
使用它来强制转换MyRow变量。我需要这个写一个通用的SUB,

可以处理任何表类型的行。


谢谢


问候

Hi

I have a data row variable which could be for any of a number of tables in
my apps. How can I type cast the variable to correct type at runtime? I know
I can get the type description using MyRow.ToString but don''t know how to
use this to typecast MyRow variable. I need this to write a generic SUB that
can deal with rows of any table type.

Thanks

Regards



假设Row继承自DataRow,那么这就是你将要使用的类型。


-

Tom Shelton

Assuming that Row inherits from DataRow, then that is the type you would
be working with.

--
Tom Shelton


这篇关于在不知道演员的情况下进行类型转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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