我正在为我在学校的类(class)开发一个程序,我正在设置自动更新。有没有办法让“else if (webClient.DownloadString("mylink").Contains("0.3.9"))”检查链接的包含以查看它是否超过或大于 0.3.9?
public Form1()
{
InitializeComponent();
WebClient webClient = new WebClient();
if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\DesktopReborn\\updates\\Update-0.4.0.xml")) { }
else if (webClient.DownloadString("mylink").Contains("0.3.9"))
{
if (MessageBox.Show("An Update is Avaliable, Would you like to download it?", "DesktopReborn Updater", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
{
webClient.DownloadFile("myupdate", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\DesktopReborn\\DesktopReborn.exe");
if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\DesktopReborn\\updates\\Update-0.3.9.xml"))
{
File.Copy(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\DesktopReborn\\updates\\Update-0.3.9.xml", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\DesktopReborn\\updates\\Update-0.4.0.xml", true);
File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\DesktopReborn\\updates\\Update-0.3.9.xml");
}
}
}
}
最佳答案
您可以使用 Version
类来解析和比较这样的字符串,例如:
string thisVersion = "0.3.9";
string newVersion = "0.4.0";
if (Version.Parse(newVersion) > Version.Parse(thisVersion))
{
Console.WriteLine($"{newVersion} is greater than {thisVersion}");
}
输出
关于C# 如何检查数字是否更大?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53126933/