Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert string into version in .net 3.5?

Tags:

c#

.net

version

I want to compare the software version created in 3.5 with the older one. If I try to compare version in 4.0 then it's easy by using Version.Parse but in earlier version this facility is not there. I tried to compare it by using string comparison but still not able get the desired output because string comparison doesn't allow to me compare with minor version or major version. Thanks in advance.

like image 288
RaviKant Hudda Avatar asked Oct 27 '14 05:10

RaviKant Hudda


People also ask

Can we convert string to object C#?

Deserialization is the process of parsing a string into an object of a specific type. The JsonSerializer. Deserialize() method converts a JSON string into an object of the type specified by a generic type parameter.

What is the current version of C#?

NET. As of July 2022, the most recent stable version of the language is C# 10.0, which was released in 2021 in .


1 Answers

Forgive me if im missing something but can't you use the version object constructor passing your version string:

http://msdn.microsoft.com/en-us/library/y0hf9t2e%28v=vs.90%29.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

string str = "0.1.2.3";
Version v = new Version(str);

This is present in the following .NET Frameworks:

4.8, 4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0, 1.1

like image 55
apc Avatar answered Sep 29 '22 07:09

apc