本文整理汇总了C#中System.Data.SqlTypes.SqlMoney.ToSqlByte方法的典型用法代码示例。如果您正苦于以下问题:C# SqlMoney.ToSqlByte方法的具体用法?C# SqlMoney.ToSqlByte怎么用?C# SqlMoney.ToSqlByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlTypes.SqlMoney
的用法示例。
在下文中一共展示了SqlMoney.ToSqlByte方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToSqlByte
/// <summary>
/// Converts the value of the specified SqlMoney to its equivalent SqlByte representation.
/// </summary>
/// <param name="value">An SqlMoney.</param>
/// <returns>The equivalent SqlByte.</returns>
public static SqlByte ToSqlByte(SqlMoney value) { return value.ToSqlByte(); }
示例2: Conversions
public void Conversions()
{
SqlMoney TestMoney100 = new SqlMoney (100);
// ToDecimal
Assert.AreEqual ( (decimal)6464.6464, Test1.ToDecimal (), "#M01");
// ToDouble
Assert.AreEqual ( (double)6464.6464, Test1.ToDouble (), "#M02");
// ToInt32
Assert.AreEqual ( (int)90000, Test2.ToInt32 (), "#M03");
Assert.AreEqual ( (int)6465, Test1.ToInt32 (), "#M04");
// ToInt64
Assert.AreEqual ( (long)90000, Test2.ToInt64 (), "#M05");
Assert.AreEqual ( (long)6465, Test1.ToInt64 (), "#M06");
// ToSqlBoolean ()
Assert.IsTrue (Test1.ToSqlBoolean ().Value, "#M07");
Assert.IsTrue (!SqlMoney.Zero.ToSqlBoolean ().Value, "#M08");
Assert.IsTrue (SqlMoney.Null.ToSqlBoolean ().IsNull, "#M09");
// ToSqlByte ()
Assert.AreEqual ( (byte)100, TestMoney100.ToSqlByte ().Value, "#M10");
try {
SqlByte b = (byte)Test2.ToSqlByte ();
Assert.Fail ("#M11");
} catch (Exception e) {
Assert.AreEqual ( typeof (OverflowException), e.GetType (), "#M12");
}
// ToSqlDecimal ()
Assert.AreEqual ( (decimal)6464.6464, Test1.ToSqlDecimal ().Value, "#M13");
Assert.AreEqual ( -45000.0000m, Test4.ToSqlDecimal ().Value, "#M14");
// ToSqlInt16 ()
Assert.AreEqual ( (short)6465, Test1.ToSqlInt16 ().Value, "#M15");
try {
SqlInt16 test = SqlMoney.MaxValue.ToSqlInt16().Value;
Assert.Fail ("#M17");
} catch (Exception e) {
Assert.AreEqual ( typeof (OverflowException), e.GetType (), "#M18");
}
// ToSqlInt32 ()
Assert.AreEqual ( (int)6465, Test1.ToSqlInt32 ().Value, "#M19");
Assert.AreEqual ( (int)(-45000), Test4.ToSqlInt32 ().Value, "#M20");
try {
SqlInt32 test = SqlMoney.MaxValue.ToSqlInt32 ().Value;
Assert.Fail ("#M21");
} catch (Exception e) {
Assert.AreEqual ( typeof (OverflowException), e.GetType (), "#M22");
}
// ToSqlInt64 ()
Assert.AreEqual ( (long)6465, Test1.ToSqlInt64 ().Value, "#M23");
Assert.AreEqual ( (long)(-45000), Test4.ToSqlInt64 ().Value, "#M24");
// ToSqlSingle ()
Assert.AreEqual ( (float)6464.6464, Test1.ToSqlSingle ().Value, "#M25");
// ToSqlString ()
Assert.AreEqual ( "6464.6464", Test1.ToSqlString ().Value, "#M26");
Assert.AreEqual ( "90000.00", Test2.ToSqlString ().Value, "#M27");
// ToString ()
Assert.AreEqual ( "6464.6464", Test1.ToString (), "#M28");
Assert.AreEqual ( "90000.00", Test2.ToString (), "#M29");
}
示例3: ToSqlByte
/// <summary>Converts the value from <c>SqlMoney</c> to an equivalent <c>SqlByte</c> value.</summary>
public static SqlByte ToSqlByte(SqlMoney p) { return p.ToSqlByte(); }
示例4: Conversions
public void Conversions()
{
SqlMoney TestMoney100 = new SqlMoney(100);
// ToDecimal
Assert.Equal((decimal)6464.6464, _test1.ToDecimal());
// ToDouble
Assert.Equal(6464.6464, _test1.ToDouble());
// ToInt32
Assert.Equal(90000, _test2.ToInt32());
Assert.Equal(6465, _test1.ToInt32());
// ToInt64
Assert.Equal(90000, _test2.ToInt64());
Assert.Equal(6465, _test1.ToInt64());
// ToSqlBoolean ()
Assert.True(_test1.ToSqlBoolean().Value);
Assert.True(!SqlMoney.Zero.ToSqlBoolean().Value);
Assert.True(SqlMoney.Null.ToSqlBoolean().IsNull);
// ToSqlByte ()
Assert.Equal((byte)100, TestMoney100.ToSqlByte().Value);
try
{
SqlByte b = (byte)_test2.ToSqlByte();
Assert.False(true);
}
catch (Exception e)
{
Assert.Equal(typeof(OverflowException), e.GetType());
}
// ToSqlDecimal ()
Assert.Equal((decimal)6464.6464, _test1.ToSqlDecimal().Value);
Assert.Equal(-45000.0000m, _test4.ToSqlDecimal().Value);
// ToSqlInt16 ()
Assert.Equal((short)6465, _test1.ToSqlInt16().Value);
try
{
SqlInt16 test = SqlMoney.MaxValue.ToSqlInt16().Value;
Assert.False(true);
}
catch (Exception e)
{
Assert.Equal(typeof(OverflowException), e.GetType());
}
// ToSqlInt32 ()
Assert.Equal(6465, _test1.ToSqlInt32().Value);
Assert.Equal(-45000, _test4.ToSqlInt32().Value);
try
{
SqlInt32 test = SqlMoney.MaxValue.ToSqlInt32().Value;
Assert.False(true);
}
catch (Exception e)
{
Assert.Equal(typeof(OverflowException), e.GetType());
}
// ToSqlInt64 ()
Assert.Equal(6465, _test1.ToSqlInt64().Value);
Assert.Equal(-45000, _test4.ToSqlInt64().Value);
// ToSqlSingle ()
Assert.Equal((float)6464.6464, _test1.ToSqlSingle().Value);
// ToSqlString ()
Assert.Equal("6464.6464", _test1.ToSqlString().Value);
Assert.Equal("90000.00", _test2.ToSqlString().Value);
// ToString ()
Assert.Equal("6464.6464", _test1.ToString());
Assert.Equal("90000.00", _test2.ToString());
}