Skip to content

Unit conversions for collections #913

Answered by angularsen
md-amf1 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, there is nothing in the library for collections specifically, but your approach works and you can also consider using LINQ to simplify slightly:

// LINQPad
void Main()
{
	ToSI(new double[] { 1, 2, 3}, LengthUnit.Centimeter).Dump();
}

public double[] ToSI(double[] values, LengthUnit unit)
{
	return values.Select(val => Length.From(val, unit).ToUnit(UnitSystem.SI).Value).ToArray();
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@md-amf1
Comment options

@angularsen
Comment options

Answer selected by md-amf1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants