0

所以我在网上找到了这段代码(通常我做 C#,但我想向我的朋友教 smallbasic),它基本上读取一个文件:

TextWindow.Write("Enter the name of the new directory: ")
DirectoryName = TextWindow.Read()
files = File.GetFiles(DirectoryName)        
TextWindow.WriteLine("This is the content in the file: ")   
TextWindow.WriteLine(File.ReadContents(files[1])) 

我理解这一切的作用,但为什么需要它files[1]而不是 just files

删除索引[1]只会使该行不起作用,程序仍然可以编译等等。

SB没有调试器,网上的资源也不是很好。

4

1 回答 1

0

根据API文档,File.GetFiles返回一个数组:

如果操作成功,这会将文件作为数组返回。否则,它将返回“FAILED”。

您指定一个索引,因为它返回一个数组并File.ReadContents需要一个实例。

在此处查看 API:http ://smallbasic.com/doc/?id=6

于 2013-09-22T17:57:57.620 回答