0
我们正在进行软件构建并将它们存储在预发布文件夹中的文件夹中,格式为四位数的Major.Minor.Build.rev(0.0.0.0)格式。如何在最新版本文件夹的LINQ查询中使用版本类
- 我想知道是否有方法在LINQ查询中使用版本类?
- 使用LINQ查询会有什么好处,还是应该坚持使用非LINQ查询代码?
下面是代码我目前:
static void Main(string[] args)
{
string latest = GetLatestBuildVersion(@"\\path\to\network\folder");
latest = "";
}
static string GetLatestBuildVersion(string sPath)
{
Version latestVersion = new Version();
string[] dirs = Directory.GetDirectories(sPath);
foreach (string dir in dirs)
{
string subfolderNameOnly = Path.GetFileName(dir);
try
{
Version subfolderVersion = new Version(subfolderNameOnly);
if (latestVersion.CompareTo(subfolderVersion) < 0)
{
latestVersion = subfolderVersion;
}
}
catch (Exception ex)
{
// Just continue
}
}
return latestVersion.ToString();
}
如果你已经有可用的代码,它看起来像哟你应该坚持下去。任何获得的优势都会很小。 – Chris
它确实有效。我希望用更少的代码来完成。我有一些代码可以在这里查询,但是我被困在Path.GetFileName和subfolderversion的版本类的第二个实例化中。 –