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


C# Unit.Convert方法代码示例

本文整理汇总了C#中Unit.Convert方法的典型用法代码示例。如果您正苦于以下问题:C# Unit.Convert方法的具体用法?C# Unit.Convert怎么用?C# Unit.Convert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Unit的用法示例。


在下文中一共展示了Unit.Convert方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConvertFunc

        private Func<CommandEventArgs, Task> ConvertFunc() =>
            async e =>
            {
                try
                {
                    await e.Channel.SendIsTyping();

                    string from = e.GetArg("from-to").ToLowerInvariant().Split('>')[0];
                    string to = e.GetArg("from-to").ToLowerInvariant().Split('>')[1];

                    float quantity = 1.0f;
                    if (!float.TryParse(e.GetArg("quantity"), out quantity))
                    {
                        quantity = 1.0f;
                    }

                    int fromCode, toCode = 0;
                    UnitTable table = null;
                    ResolveUnitCodes(from, to, out table, out fromCode, out toCode);

                    if (table != null)
                    {
                        Unit inUnit = new Unit(fromCode, quantity, table);
                        Unit outUnit = inUnit.Convert(toCode);
                        await e.Channel.SendMessage(inUnit.ToString() + " = " + outUnit.ToString());
                    }
                    else
                    {
                        reInitCurrencyConverterTable();
                        Unit inUnit = currTable.CreateUnit(quantity, from.ToUpperInvariant());
                        Unit outUnit = inUnit.Convert(currTable.CurrencyCode(to.ToUpperInvariant()));
                        await e.Channel.SendMessage(inUnit.ToString() + " = " + outUnit.ToString());
                    }
                }
                catch //(Exception ex)
                {
                    //Console.WriteLine(ex.ToString());
                    await e.Channel.SendMessage("Bad input format, or sth went wrong... Try to list them with `" + Module.Prefix + "`convertlist");
                }
            };
开发者ID:magicvoid1,项目名称:NadekoBot,代码行数:40,代码来源:ConverterCommand.cs

示例2: Vector2d

 /// <summary>
 /// Create new vector from two distance values and specified unit types
 /// </summary>
 /// <param name="x">X value</param>
 /// <param name="y">Y value</param>
 /// <param name="unitX">Unit type for X</param>
 /// <param name="unitY">Unit type for Y</param>
 public Vector2d(double x, double y, Unit unitX, Unit unitY)
 {
     this.unit = unitX;
     this.x = x;
     this.y = unitY.Convert(y, unitX);
 }
开发者ID:Nercury,项目名称:RealUnits,代码行数:13,代码来源:Vector2d.cs

示例3: Vector2f

 /// <summary>
 /// Create new vector from two distance values and specified unit types
 /// </summary>
 /// <param name="x">X value</param>
 /// <param name="y">Y value</param>
 /// <param name="unitX">Unit type for X</param>
 /// <param name="unitY">Unit type for Y</param>
 public Vector2f(float x, float y, Unit unitX, Unit unitY)
 {
     this.unit = unitX;
     this.x = x;
     this.y = unitY.Convert(y, unitX);
 }
开发者ID:Nercury,项目名称:RealUnits,代码行数:13,代码来源:Vector2f.cs

示例4: Rectangle2f

 /// <summary>
 /// Create new vector from two distance values and specified unit types
 /// </summary>
 /// <param name="x">X value</param>
 /// <param name="y">Y value</param>
 /// <param name="width">Width value</param>
 /// <param name="height">Height value</param>
 /// <param name="unitX">Unit type for X</param>
 /// <param name="unitY">Unit type for Y</param>
 /// <param name="unitW">Unit type for width</param>
 /// <param name="unitH">Unit type for height</param>
 public Rectangle2f(float x, float y, float width, float height, Unit unitX, Unit unitY, Unit unitW, Unit unitH)
 {
     this.unit = unitX;
     this.x = x;
     this.y = unitY.Convert(y, unitX);
     this.w = unitW.Convert(width, unitX);
     this.h = unitH.Convert(height, unitX);
 }
开发者ID:Nercury,项目名称:RealUnits,代码行数:19,代码来源:Rectangle2f.cs

示例5: Rectangle2d

 /// <summary>
 /// Create new vector from two distance values and specified unit types
 /// </summary>
 /// <param name="x">X value</param>
 /// <param name="y">Y value</param>
 /// <param name="width">Width value</param>
 /// <param name="height">Height value</param>
 /// <param name="unitX">Unit type for X</param>
 /// <param name="unitY">Unit type for Y</param>
 /// <param name="unitW">Unit type for width</param>
 /// <param name="unitH">Unit type for height</param>
 public Rectangle2d(double x, double y, double width, double height, Unit unitX, Unit unitY, Unit unitW, Unit unitH)
 {
     this.unit = unitX;
     this.x = x;
     this.y = unitY.Convert(y, unitX);
     this.w = unitW.Convert(width, unitX);
     this.h = unitH.Convert(height, unitX);
 }
开发者ID:Nercury,项目名称:RealUnits,代码行数:19,代码来源:Rectangle2d.cs


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