本文整理汇总了C#中Distance.ToMeters方法的典型用法代码示例。如果您正苦于以下问题:C# Distance.ToMeters方法的具体用法?C# Distance.ToMeters怎么用?C# Distance.ToMeters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Distance
的用法示例。
在下文中一共展示了Distance.ToMeters方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestConvertion
public void TestConvertion()
{
// Create an object with 5 m
Distance dist = new Distance(5, DistanceUnit.Meters);
Assert.AreEqual(5, dist.Value);
Assert.AreEqual(DistanceUnit.Meters, dist.Units);
Distance feet = dist.ToFeet();
Assert.AreEqual(16.4041995, feet.Value, 0.00001);
Assert.AreEqual(DistanceUnit.Feet, feet.Units);
Distance meters = dist.ToMeters();
Assert.AreEqual(5, meters.Value);
Assert.AreEqual(DistanceUnit.Meters, meters.Units);
Distance mm = dist.ToMillimeters();
Assert.AreEqual(5000, mm.Value);
Assert.AreEqual(DistanceUnit.Millimeters, mm.Units);
Distance cm = dist.ToCentimeters();
Assert.AreEqual(500, cm.Value);
Assert.AreEqual(DistanceUnit.Centimeters, cm.Units);
Distance inch = dist.ToInches();
Assert.AreEqual(196.850394, inch.Value, 0.00001);
Assert.AreEqual(DistanceUnit.Inches, inch.Units);
Distance km = dist.ToKilometers();
Assert.AreEqual(0.005, km.Value);
Assert.AreEqual(DistanceUnit.Kilometers, km.Units);
Distance miles = dist.ToStatuteMiles();
Assert.AreEqual(0.00310685596, miles.Value, 0.00001);
Assert.AreEqual(DistanceUnit.StatuteMiles, miles.Units);
Distance nm = dist.ToNauticalMiles();
Assert.AreEqual(0.00269978402, nm.Value, 0.00001);
Assert.AreEqual(DistanceUnit.NauticalMiles, nm.Units);
}
示例2: GpggaSentence
public GpggaSentence(TimeSpan utcTime, Position position, FixQuality fixQuality, int trackedSatelliteCount,
DilutionOfPrecision horizontalDilutionOfPrecision, Distance altitude, Distance geoidalSeparation,
TimeSpan differentialGpsAge, int differentialGpsStationID)
{
// Use a string builder to create the sentence text
StringBuilder builder = new StringBuilder(128);
#region Append the command word
// Append the command word
builder.Append("$GPGGA");
#endregion
// Append a comma
builder.Append(',');
#region Append the UTC time
/* Convert UTC time to a string in the form HHMMSS.SSSS. Any value less than 10 will be
* padded with a zero.
*/
builder.Append(_UtcTime.Hours.ToString("0#", NmeaCultureInfo));
builder.Append(_UtcTime.Minutes.ToString("0#", NmeaCultureInfo));
builder.Append(_UtcTime.Seconds.ToString("0#", NmeaCultureInfo));
builder.Append(".");
builder.Append(_UtcTime.Milliseconds.ToString("00#", NmeaCultureInfo));
#endregion
// Append a comma
builder.Append(',');
#region Append the position
// Append latitude in the format HHMM.MMMM.
builder.Append(position.Latitude.ToString("HHMM.MMMM,I,", NmeaCultureInfo));
// Append Longitude in the format HHHMM.MMMM.
builder.Append(position.Longitude.ToString("HHHMM.MMMM,I,", NmeaCultureInfo));
#endregion
#region Append fix quality
switch (fixQuality)
{
case FixQuality.NoFix:
builder.Append("0");
break;
case FixQuality.GpsFix:
builder.Append("1");
break;
case FixQuality.DifferentialGpsFix:
builder.Append("2");
break;
case FixQuality.PulsePerSecond:
builder.Append("3");
break;
case FixQuality.FixedRealTimeKinematic:
builder.Append("4");
break;
case FixQuality.FloatRealTimeKinematic:
builder.Append("5");
break;
case FixQuality.Estimated:
builder.Append("6");
break;
case FixQuality.ManualInput:
builder.Append("7");
break;
case FixQuality.Simulated:
builder.Append("8");
break;
}
#endregion
// Append a comma
builder.Append(",");
// Append the tracked (signal strength is > 0) satellite count
builder.Append(trackedSatelliteCount.ToString(NmeaCultureInfo));
// Append a comma
builder.Append(",");
// Append the numerical value of HDOP
builder.Append(horizontalDilutionOfPrecision.Value.ToString(NmeaCultureInfo));
// Append a comma
builder.Append(",");
#region Altitude above sea level
// Append the numerical value in meters
builder.Append(altitude.ToMeters().Value.ToString(NmeaCultureInfo));
// Append a comma, the unit (M = meters), and another comma
builder.Append(",M,");
//.........这里部分代码省略.........
示例3: ConvertToMetersWorksCorrectly
public void ConvertToMetersWorksCorrectly()
{
// Arrange
const double Millimeters = 112345;
const double Meters = 112.345;
// Act
var distance = new Distance(Millimeters);
// Assert
Assert.IsNotNull(distance);
Assert.AreEqual(Meters, distance.ToMeters());
}