当前位置: 首页>>代码示例>>C#>>正文


C# Measurement.ToString方法代码示例

本文整理汇总了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");
        }
开发者ID:hartez,项目名称:Convertinator,代码行数:7,代码来源:MeasurementOutputTests.cs

示例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");
        }
开发者ID:hartez,项目名称:Convertinator,代码行数:33,代码来源:ReadmeExamples.cs

示例3: OneUnitExplicitDisplayName

        public void OneUnitExplicitDisplayName()
        {
            var meter = new Unit("meter")
                .DisplayWithName("metre");
            var oneMeter = new Measurement(meter, 1M);

            oneMeter.ToString().Should().Be("1 metre");
        }
开发者ID:hartez,项目名称:Convertinator,代码行数:8,代码来源:MeasurementOutputTests.cs

示例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");
        }
开发者ID:hartez,项目名称:Convertinator,代码行数:9,代码来源:MeasurementOutputTests.cs

示例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");
        }
开发者ID:hartez,项目名称:Convertinator,代码行数:10,代码来源:MeasurementOutputTests.cs

示例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";
//.........这里部分代码省略.........
开发者ID:ashish-antil,项目名称:Products,代码行数:101,代码来源:TestProgram.cs

示例7: MeasurementToStringTest

 public void MeasurementToStringTest()
 {
     Measurement target = new Measurement (10, "ft");
     string expected = "10ft";
     string actual = null;
     actual = target.ToString ();
     Assert.AreEqual (expected, actual);
 }
开发者ID:irperez,项目名称:Cubico,代码行数:8,代码来源:MeasurementTests.cs


注:本文中的Measurement.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。