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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -