帮助数组 [英] Help with array

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

问题描述

我想从文本框中输入的路径中提取文件名

这样做:


string sFile = File1。值;

string [] sArray = sFile.Split(new char [] {''/''});

sFile = sArray.GetValue(sArray.GetUpperBound( 0));


但是,我收到以下错误:

编译器错误消息:CS0029:无法将类型''object'隐式转换为

''字符串''


我无法弄清楚如何纠正这个问题。有人可以帮我吗?


谢谢!


-
http://www.vbmark.com/

一个好的起点。

I''m tyring to extract the file name from a path entered in a text box by
doing this:

string sFile = File1.Value;
string[] sArray = sFile.Split(new char[] {''/''});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

However, I get the following error:
Compiler Error Message: CS0029: Cannot implicitly convert type ''object'' to
''string''

I can''t figure out how to correct this. Can someone help me here?

Thanks!

--
http://www.vbmark.com/
A good place to start.

推荐答案

sFile =(string)sArray.GetValue(sArray.GetUpperBound(0));
GetValue返回一个对象。另外你应该使用索引器[]来

以类型安全的方式访问数组的元素。


-

John Wood

电子邮件:名字,点,姓,在priorganize.com

" vbMark" < no@email.com>在消息中写道

新闻:Xn ************************ @ 130.133.1.4 ...我正在打扰通过以下方式从文本框中输入的路径中提取文件名:

string sFile = File1.Value;
string [] sArray = sFile.Split(new char [] {''/''});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

但是,我收到以下错误:
编译器错误消息:CS0029:无法隐式转换类型''object''到
''string''

我无法弄清楚如何纠正这个问题。有人可以帮我吗?

谢谢!

http://www.vbmark.com/
一个好的起点。
sFile = (string)sArray.GetValue(sArray.GetUpperBound(0)); GetValue returns an object. Alternative you should use the indexer [] to
access the elements of the array in a type-safe manner.

--
John Wood
EMail: first name, dot, last name, at priorganize.com
"vbMark" <no@email.com> wrote in message
news:Xn************************@130.133.1.4... I''m tyring to extract the file name from a path entered in a text box by
doing this:

string sFile = File1.Value;
string[] sArray = sFile.Split(new char[] {''/''});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

However, I get the following error:
Compiler Error Message: CS0029: Cannot implicitly convert type ''object'' to
''string''

I can''t figure out how to correct this. Can someone help me here?

Thanks!

--
http://www.vbmark.com/
A good place to start.



sFile =(string)sArray.GetValue(sArray.GetUpperBound(0));
GetValue返回一个对象。另外你应该使用索引器[]来

以类型安全的方式访问数组的元素。


-

John Wood

电子邮件:名字,点,姓,在priorganize.com

" vbMark" < no@email.com>在消息中写道

新闻:Xn ************************ @ 130.133.1.4 ...我正在打扰通过以下方式从文本框中输入的路径中提取文件名:

string sFile = File1.Value;
string [] sArray = sFile.Split(new char [] {''/''});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

但是,我收到以下错误:
编译器错误消息:CS0029:无法隐式转换类型''object''到
''string''

我无法弄清楚如何纠正这个问题。有人可以帮我吗?

谢谢!

http://www.vbmark.com/
一个好的起点。
sFile = (string)sArray.GetValue(sArray.GetUpperBound(0)); GetValue returns an object. Alternative you should use the indexer [] to
access the elements of the array in a type-safe manner.

--
John Wood
EMail: first name, dot, last name, at priorganize.com
"vbMark" <no@email.com> wrote in message
news:Xn************************@130.133.1.4... I''m tyring to extract the file name from a path entered in a text box by
doing this:

string sFile = File1.Value;
string[] sArray = sFile.Split(new char[] {''/''});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

However, I get the following error:
Compiler Error Message: CS0029: Cannot implicitly convert type ''object'' to
''string''

I can''t figure out how to correct this. Can someone help me here?

Thanks!

--
http://www.vbmark.com/
A good place to start.



vbMark< no@email.com>写道:
vbMark <no@email.com> wrote:
我正在通过这样做来从文本框中输入的路径中提取文件名:

string sFile = File1.Value ;
string [] sArray = sFile.Split(new char [] {''/''}};
sFile = sArray.GetValue(sArray.GetUpperBound(0));
<但是,我收到以下错误:
编译器错误消息:CS0029:无法将类型''对象'隐式转换为
''字符串''

我可以弄清楚如何纠正这个问题。有人可以帮助我吗?
I''m tyring to extract the file name from a path entered in a text box by
doing this:

string sFile = File1.Value;
string[] sArray = sFile.Split(new char[] {''/''});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

However, I get the following error:
Compiler Error Message: CS0029: Cannot implicitly convert type ''object'' to
''string''

I can''t figure out how to correct this. Can someone help me here?




最简单的办法是避免使用Array方法,只需使用

正常即可。访问数组的方式:


sFile = sArray [sArray.Length-1];


要更正现有代码,您只需添加一个演员阵容

虽然。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件



The easiest thing to do is avoid using the Array methods, and just use
the "normal" way of accessing arrays:

sFile = sArray[sArray.Length-1];

To correct your existing code, you could just add a cast to string
though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


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

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