编辑:
我要如何检查的简单示例:
我有一个string
包含:“0101”。
我想检查它string
是否至少为 0101 或更高,而不将其转换为int
,因为这会将我的更改string
为:101。
编辑:
答案如下所示:
private void VersionCheck(string version)
{
string firmwareVersion = version.Substring(0, 4);
string biosVersion = version.Substring(4, 4);
var isEqualOrHigherFirmwareVersion = string.Compare(firmwareVersion, Settings.MinimalFirmwareUnikon, CultureInfo.InvariantCulture, CompareOptions.None) >= 0;
if (!isEqualOrHigherFirmwareVersion)
{
_serial.ClosePortConnection();
DisplayLog("CLOCK: Firmware NOT OK : Unsupported version");
MessageBox.Show("Unsupported clock Firmware!", "Firmware", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
DisplayLog("CLOCK: Firmware OK : v" + firmwareVersion.ToString());
}
var isEqualOrHigherBiosVersion = string.Compare(biosVersion, `Settings.MinimalBiosUnikon, CultureInfo.InvariantCulture, CompareOptions.None) >= 0;`
if (!isEqualOrHigherBiosVersion)
{
_serial.ClosePortConnection();
DisplayLog("CLOCK: BIOS NOT OK : Unsupported version");
MessageBox.Show("Unsupported clock BIOS version!", "BIOS", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
DisplayLog("CLOCK: BIOS OK : v" + biosVersion.ToString());
}
}