本文整理汇总了C#中Measurement.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Measurement.ToString方法的具体用法?C# Measurement.ToString怎么用?C# Measurement.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Measurement
的用法示例。
在下文中一共展示了Measurement.ToString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OneUnitDefaultName
public void OneUnitDefaultName()
{
var meter = new Unit("meter");
var oneMeter = new Measurement(meter, 1M);
oneMeter.ToString().Should().Be("1 meter");
}
示例2: UnitNames
public void UnitNames()
{
var meter = new Unit("meter")
.IsAlsoCalled("metre")
.CanBeAbbreviated("m", "mtr")
.UsePluralFormat("{0}s");
var feet = new Unit("foot")
.PluralizeAs("feet")
.CanBeAbbreviated("ft");
var system = new ConversionGraph()
.RoundToDecimalPlaces(5);
system.AddConversion(Conversions.One(meter).In(feet).Is(3.28084M));
var meterMeasurement = new Measurement(meter, 1);
var feetMeasurement = new Measurement(feet, 2);
var x = system.Convert(meterMeasurement, feet);
Assert.That(system.Convert(meterMeasurement, feet) == 3.28084M);
Assert.That(system.Convert(meterMeasurement, "ft") == 3.28084M);
Assert.That(system.Convert(feetMeasurement, "metre") == 0.6096M);
Assert.That(system.Convert(feetMeasurement, "mtr") == 0.6096M);
Assert.That(system.Convert(feetMeasurement, "m") == 0.6096M);
Assert.That(meterMeasurement.ToAbbreviatedString() == "1 m");
Assert.That(meterMeasurement.ToString() == "1 meter");
Assert.That(feetMeasurement.ToAbbreviatedString() == "2 ft");
Assert.That(feetMeasurement.ToString() == "2 feet");
}
示例3: OneUnitExplicitDisplayName
public void OneUnitExplicitDisplayName()
{
var meter = new Unit("meter")
.DisplayWithName("metre");
var oneMeter = new Measurement(meter, 1M);
oneMeter.ToString().Should().Be("1 metre");
}
示例4: MultipleUnitsPlural
public void MultipleUnitsPlural()
{
var meter = new Unit("meter")
.UsePluralFormat("{0}s");
var twoMeters = new Measurement(meter, 2M);
twoMeters.ToString().Should().Be("2 meters");
}
示例5: MultipleUnitsExplicitDisplayNameAndPluralFormat
public void MultipleUnitsExplicitDisplayNameAndPluralFormat()
{
var meter = new Unit("meter")
.DisplayWithName("metre")
.UsePluralFormat("{0}s");
var measure = new Measurement(meter, 5M);
measure.ToString().Should().Be("5 metres");
}
示例6: Main
static void Main(string[] args)
{
Console.WindowHeight = 60;
var ci = new CultureInfo("en-NZ");
var mfi = new MeasurementFormatInfo(ci.NumberFormat);
var dict = new HybridDictionary();
dict["FuelEfficiency"] = "km/L;0.0";
dict["Length"] = "in";
dict["MassFlow"] = "t/d;0.00000";
dict["Angle"] = ">+0d0'0.00\"";
dict["Angle~brg"] = "<{>B} ({>+000d})";
dict["Angle~test"] = "<{~brg} {/3.1415926536;0.00}\u03C0 {!;0.0} {*} {%} {>x}";
mfi.SetPreferences(dict);
var ang1 = Angle.Degrees(-25);
string sAng1 = ang1.ToString("~test", mfi);
Console.WriteLine("composite format: 25deg: {0}", sAng1);
var ang2 = Angle.Degrees(333);
string sAng2 = ang2.ToString("~brg", mfi);
Console.WriteLine("composite format: 333deg: {0} {1:>X}", sAng2, ang2);
for (int deg3 = 0; deg3 < 700; deg3 += 50)
{
Angle ang3 = Angle.Degrees(deg3);
string sAng3 = ang3.ToString("<{!},{>0d},{>+0d},{>-000d00'00.0\"}", mfi);
Console.WriteLine("normal, full and half: {0}", sAng3);
}
string x1 = string.Format(mfi,
"\r\nUnitless: {0:*}" + // unitless SI value
"\r\nKnown unit: {1:km/L}" + // use km/L unit
"\r\nMultiplier: {2:*3.6;0,000.000}" + // unitless, multiply SI value
"\r\nCanonical: {3:!;0.00}" + // show simple SI base units with dots between units
"\r\nSI base: {4:^}" + // show simple SI base units without dots between, and using superscripts for 1..3
"\r\nAngle: {5:deg;0.0}" + // display unit different from the lookup key
"\r\nCurrency: {6:@}" + // @ is the lookup character for the generic currency symbol
"\r\nTemperature: {7:degF;0.0}" + // temperature scale conversion
"\r\nFeet: {8:';30.0}" + // use of ' mark
"\r\nPreferred: {9}" + // uses the preferences in MeasureFormatInfo
"\r\nEasy unit: {10: m3}" + // converts 3 to superscript before lookup
"\r\nSlash unit: {11:ps;0}" // 'per' ...
, Length.Metre(10) //0
, FuelEfficiency.KmPerLitre(11.5) //1
, Speed.MetrePerSec(893483.0) //2
, Pressure.Pascal(1013.293840129348) //3
, Volume.CubicMetre(7.0012) //4
, Angle.Degrees(89.55) //5
, new Currency(1200) //6
, Temperature.Kelvin(233.15) //7
, Length.Metre(3) //8
, MassFlow.KgPerSec(2.3) // 9
, Volume.USGallon(100.0) // 10
, Frequency.Hertz(60) // 11
);
var m1 = new Measurement(0.1334, new MUnit(2, 3, -1, 0, 0, 1, 0));
string x2 = string.Format(mfi,
"\r\nCanonical {0:!}" +
"\r\nSuperscript {1:^}" +
"\r\nUnitless {2:*}" +
"\r\nMultiplier {3:*100}%" +
"\r\nDivider {4:/2}" +
"\r\nPreferred {5}"
, m1, m1, m1, m1, m1, m1
);
Console.WriteLine(x1);
Console.WriteLine(x2);
Console.WriteLine(FuelEfficiency.USGallonPer100Mile(5.0).ToString(null, mfi));
string q;
Console.WriteLine(Angle.Degrees(-123.457).ToString(">000E 00' 00.0\"", mfi));
Console.WriteLine(q = Angle.Degrees(-123.457).ToString(">#DN 00' 00.0\"", mfi));
Console.WriteLine(Angle.Degrees(3.457).ToString(">000.00000d", mfi));
Console.WriteLine(Angle.Degrees(-6.1234123).ToString(">0.00000d 0.00000' 0.00000\u2033", mfi));
Console.WriteLine("---");
var time = Time.Hours(2);
var speed = Speed.Kph(20);
var length = (Length)((Measurement)speed * time);
Console.WriteLine(string.Format(mfi, "Length = {0:km}", length));
Console.WriteLine(Length.Metre(20).ToString("yd", mfi));
Console.WriteLine(string.Format(mfi, "-> {0}", Length.Metre(0.01)));
Console.WriteLine("=> " + Length.Metre(0.01).ToString(null, mfi));
//string s = FuelEfficiency.KmPerLitre(14.5).ToString("gal/100mi", measureFormatInfo);
string s = Angle.Degrees(45).ToString("%;0.0", mfi);
Console.WriteLine(s);
var a = Length.Metre(5e-9);
var ss = string.Format(mfi, "{0:/1e-9;0}nm = {1:*1e9;0}nm", a, a);
Console.WriteLine(ss);
ss = string.Format(mfi, "{0:*;0}nm", new Measurement(a.InSI(SIPrefix.Nano)));
Console.WriteLine(ss);
var fe1 = FuelEfficiency.KmPerLitre(11).ToString("<{km/L;0.0} ({L/100km;0})", mfi);
Console.WriteLine("FE: " + fe1);
var sp1 = Speed.Kph(5.1).ToString("<{*86.4;0}km/24h", mfi);
Console.WriteLine("Daily distance " + sp1);
string z = "Length:12";
//.........这里部分代码省略.........
示例7: MeasurementToStringTest
public void MeasurementToStringTest()
{
Measurement target = new Measurement (10, "ft");
string expected = "10ft";
string actual = null;
actual = target.ToString ();
Assert.AreEqual (expected, actual);
}