c# - What is the best way to parse a single part of a version number into a Version type -
context: want parse single part string version type:
string lversionasstring = "6";
problem: parsing version number single part results in exception:
version lversion = new version(lversionasstring); // exception
reason: version class requires minimum 2 version parts. e.g. value 6.1
so tried following simple solution:
var lversionparts = lversionasstring.split('.'); if (lversionparts.length == 1) { lversionasstring += ".0"; } version lversion = new version(lversionasstring); // works
i there better way?
you check whether number in dot format:
if(!lversionasstring.contains(".")) { lversionasstring += ".0"; }
Comments
Post a Comment