无法从int转换为ref对象 [英] cannot convert from int to ref object
问题描述
你好,
可能是初学者的问题:)
我在VB中有这个代码示例:
if(objResults.Item(1).etc
将其翻译成C#
if(objResults [1] .etc
但是编译器抱怨索引1有:无法从int转换为
ref对象。那么我在这里做错了什么?(objResults是来自
$ b的返回对象$ b MapPoint,但我觉得没关系。
-
rgds,Wilfried
http://www.mestdagh.biz
< blockquote>你好Wilfried,
我不知道这里发生了什么,但是对于那些C#需要显式演员而言,VB往往不那么严格。
转换。 br />
objResults到底是什么?它的Item集合返回什么?
基本上,一些代码会更好:)
-
H. appy Coding!
Morten Wennevik [C#MVP]
你好Wilfried,
你好,
可能是初学者的问题:)
我在VB中有这个代码示例:
if(objResults.Item(1).etc
将其转换为C#
if(objResults [1] .etc
但编译器抱怨索引''1'':无法从int转换为
ref对象。那么我在这里做错了什么? (objResults是来自MapPoint的返回对象,但我认为这并不重要。)
如果VB" Item"需要ref对象参数,然后你可以声明:
object objIndex = 1;
....并通过引用传递它如下:
objResulrs [ref objIndex] .etc
HTH
Marcin
嗨Marcin和Morton,
感谢您的回复,但是不行。我可以在Delphi8中访问索引,但是
给我其他代码completitions。所以我假设帮助和示例是
过时了。将首先检查出来。
rgds,Wilfried
Hello,
probably a beginners question :)
I have this code sample in VB:
if (objResults.Item(1).etc
Translate this into C#
if (objResults[1].etc
But compiler complains about the index ''1'' with: cannot convert from int to
ref object. So what I do wrong here ? (objResults is a returned object from
MapPoint, but that does not matter I think).
--
rgds, Wilfried
http://www.mestdagh.biz
Hi Wilfried,
I''m not sure what happens here, but VB is often less strict about
conversions where C# needs explicit casts.
What exactly is an objResults? and what does its Item collection return?
Basically, some more code would be nice :)
--
Happy Coding!
Morten Wennevik [C# MVP]
Hi Wilfried,
Hello,
probably a beginners question :)
I have this code sample in VB:
if (objResults.Item(1).etc
Translate this into C#
if (objResults[1].etc
But compiler complains about the index ''1'' with: cannot convert from int to
ref object. So what I do wrong here ? (objResults is a returned object from
MapPoint, but that does not matter I think).
If VB "Item" needs "ref object" parameter, then you can declare:
object objIndex=1;
.... and pass it by reference as follow:
objResulrs[ref objIndex].etc
HTH
Marcin
Hi Marcin and Morton,
Thanks for reply, but dont work. I can access the index in Delphi8 but it
give me other code completitions. So I assume the help and the example are
out of date. Will check that out first.
rgds, Wilfried
这篇关于无法从int转换为ref对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!