c#中的表达式术语“string”无效 [英] Invalid expression term 'string' in c#
本文介绍了c#中的表达式术语“string”无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public delegate void FileDelegate(List<string> str);
public event FileDelegate FilesCompleted;
void upload_Status(object sender, EventArgs e)
{
FileUpload fu = sender as FileUpload;
if (fu.Status == FileUploadStatus.Complete)
{
if (uploading)
UploadFiles();
if (FilesCompleted != null)
{
if (files.Count == files.Count(q => q.Status == FileUploadStatus.Complete))
FilesCompleted(files.ToList(string));
}
}
}
当我将程序填充到下面错误消息
When i Bulid the program i got below Error message
FilesCompleted(files.ToList(string));
无效的表达式术语'字符串'
请帮助我...
"Invalid expression term 'string'"
Please Help Me...
推荐答案
好的是 -字符串
是类型,str
是你显示的变量。
尝试:
Well yes -string
is the type,str
is the variable you show.
Try:
FilesCompleted(files.ToList(str));
但它可能不起作用:你没有显示代码片段的上下文,如图所示的代码将无法编译 - 因此str可能不存在于您编码的确切上下文中。
或者,比尔建议:
But it may not work: you don't show the context of the code fragment, and the code as shown won't compile - so str may not exist in the exact context you are coding.
Or, as Bill suggests:
FilesCompleted(files.ToList<string>());
但这不太可行除非你的文件类隐含转换为字符串。
尝试:
But that is unlikely to work either unless there is a implicit conversion from your file class to a string.
Try:
FilesCompleted(files.Select(f => f.Path).ToList());
假设它是你感兴趣的文件路径传递给代表。
Assuming it's the file path you are interested in passing to the delegate.
这篇关于c#中的表达式术语“string”无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文