c# - 获取目录名称的数字版本时出错

标签 c# linq compiler-errors version

我编写了一个代码来获取目录名称的版本号,例如,此文件夹名为Update5.0.1,我只需要“5.0.1”部分即可。我将目录路径传递给此函数:

public int CompareVersion(string NovoUpdate, string Config)
{
      int Status = 0;
      try
      {
          ExeConfigurationFileMap configOld = new ExeConfigurationFileMap();
          configOld.ExeConfigFilename = Config;
          Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configOld, ConfigurationUserLevel.None);
          if (config.AppSettings.Settings["Version"] != null)
          {
              string value = config.AppSettings.Settings["Version"].Value.ToString();
              Version ver = Version.Parse(value);
              Version version = null;
              Version VersionFinal = null;
              var lastVersion = new DirectoryInfo(NovoUpdate).FullName;
        //.Where(d => d.Name.StartsWith("UPDATE_"))
        .Select(d => new { Directory = d, Token = d.Name.Split('_') })
        .Where(x => x.Token.Length == 3 && Version.TryParse(x.Token[2], out version))
        .Select(x => new { x.Directory, Date = x.Token[1], Version = version })
        .OrderByDescending(x => x.Version)
        .FirstOrDefault();
              if (lastVersion != null)
              {
                  VersionFinal = Version.Parse(lastVersion.ToString());
              }

              if (ver >= VersionFinal)
                  Status = 1;
              else
                  Status = 0;
          }
          else Status = -1;
      }
      catch (Exception ex)
      {
          Erro NovoErro = new Erro();
          Program.Erro = ex.ToString();
          NovoErro.ShowDialog();
      }
      return Status;
 }

I have an error on this line:


var lastVersion = new DirectoryInfo(NovoUpdate);
            //.Where(d => d.Name.StartsWith("UPDATE_"))
            .Select(d => new { Directory = d, Token = d.Name.Split('_') })

I've alredy tried to change the "lastVersion" to string or just use the "NovoUpdate" string instead of DirectoryInfo. I dont really know how to use linq Any help would be aprecciated.

最佳答案

我认为您忘记了调用“GetDirectories”方法,例如:
new DirectoryInfo(NovoUpdate).GetDirectories().Select...

关于c# - 获取目录名称的数字版本时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36746131/

相关文章:

c# - 类型转换代表

c# - 强制执行必须在*不同*字段中的每个子类实现的属性的最佳方法是什么?

c# - 使用 LINQ 根据给定条件过滤 List<Point>

c# - 在 C# 中比较可能为空的字符串

c++ - clang 的 c++11 支持可靠吗?

c# - 当我们在 c#.net 中进行分页时, GridView 找到最后一行

c# - CouchDB 存储与 C# 中的同步(复制)

linq - 如何从 LINQ to SQL 中的子集合中删除记录?

xcode - 为什么 Xcode 的错误检查对我的测试文件夹不起作用?

compiler-errors - "handle"函数和 Real World Haskell