如何在C#中的一个函数中传回一个字符串和一个布尔值?

Mat*_*iby 1 c# arrays list

所以我有这个功能

    public bool FileExists(string path, string filename)
    {
        string fullPath = Path.Combine(path, "pool");
        string[] results = System.IO.Directory.GetFiles(fullPath, filename, SearchOption.AllDirectories);
       return (results.Length == 0 ?  false : true);
    }
Run Code Online (Sandbox Code Playgroud)

它是否在目录及其所有子目录中找到文件返回true或false ...但我想传递字符串位置

这是我怎么称呼它

            if (FileExists(location, attr.link))
            {
                FileInfo f = new FileInfo("string the file was found");
Run Code Online (Sandbox Code Playgroud)

关于如何实现这一点的任何想法?也许改成列表或数组......任何想法

Dav*_*ish 5

你的意思是你只是希望返回发现文件的所有位置?

你可以这样做:

public static string[] GetFiles(string path, string filename)
{
    string fullPath = Path.Combine(path, "pool");
    return System.IO.Directory.GetFiles(fullPath, filename, SearchOption.AllDirectories);   
}
Run Code Online (Sandbox Code Playgroud)

并使用如下:

var files = GetFiles(location, attr.link);

if (files.Any())
{
    //Do stuff
}
Run Code Online (Sandbox Code Playgroud)