日期:2014-05-17  浏览次数:21385 次

c# 关于return在foreach中的用法
我想写一个有字符串为返回值的方法,但是在方法内有foreach,如果我用了return的话,它就不往下执行了,怎么办啊?代码如下,求大神啊




public string GetFileType(string FileDirectory)
        {
            DirectoryInfo DI = new DirectoryInfo(FileDirectory);
            FileSystemInfo[] f = DI.GetFileSystemInfos();
            string Ex="";
            foreach (FileSystemInfo i in f)
            {
                if (i is DirectoryInfo)
                {
                    if ((i.Attributes & FileAttributes.Hidden) == 0)
                    {
                        Search(i.FullName);
                        return null;
                    }
 
                }
                else
                {
                    if (Ex != "")
                    {
                        Ex = i.Extension;
                        return Ex;
                    }
                    else
                    {
                        Ex = Ex + "," + i.Extension;
                        return Ex;
                    }
 
 
                }
    &n