gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:01:36 24 4
gpt4 key购买 nike

我编写了一个代码来获取目录名称的版本号,例如,此文件夹名为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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com