问题描述
我想从文本框中输入的路径中提取文件名
这样做:
string sFile = File1。值;
string [] sArray = sFile.Split(new char [] {''/''});
sFile = sArray.GetValue(sArray.GetUpperBound( 0));
但是,我收到以下错误:
编译器错误消息:CS0029:无法将类型''object'隐式转换为
''字符串''
我无法弄清楚如何纠正这个问题。有人可以帮我吗?
谢谢!
-
一个好的起点。
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.
推荐答案
最简单的办法是避免使用Array方法,只需使用
正常即可。访问数组的方式:
sFile = sArray [sArray.Length-1];
要更正现有代码,您只需添加一个演员阵容
虽然。
-
Jon Skeet - < sk *** @ pobox.com>
如果回复小组,请不要给我发邮件
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
这篇关于帮助数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!