本文整理汇总了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");
}
};
示例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);
}
示例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);
}
示例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);
}
示例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);
}