本文整理汇总了C#中Integer32.ToBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Integer32.ToBytes方法的具体用法?C# Integer32.ToBytes怎么用?C# Integer32.ToBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Integer32
的用法示例。
在下文中一共展示了Integer32.ToBytes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestNegative
public void TestNegative()
{
const int i = -2147418240;
Integer32 data = new Integer32(i);
byte[] bytes = data.ToBytes();
Integer32 other = (Integer32)DataFactory.CreateSnmpData(bytes);
Assert.AreEqual(i, other.ToInt32());
}
示例2: TestNegative2
public void TestNegative2()
{
// bug 7217 http://sharpsnmplib.codeplex.com/workitem/7217
Integer32 i = new Integer32(-250);
var result = DataFactory.CreateSnmpData(i.ToBytes());
Assert.AreEqual(SnmpType.Integer32, result.TypeCode);
Assert.AreEqual(-250, ((Integer32)result).ToInt32());
}
示例3: TestNegative3
public void TestNegative3()
{
// #7240
const int i = -237053658;
Integer32 data = new Integer32(i);
byte[] bytes = data.ToBytes();
Assert.AreEqual(6, bytes.Length);
var exception = Assert.Throws<ArgumentException>(() => DataFactory.CreateSnmpData(new byte[] { 0x02, 0x05, 0xFF, 0xF1, 0xDE, 0xD9, 0x26 }));
Assert.AreEqual("truncation error for 32-bit integer coding\r\nParameter name: length", exception.Message);
}
示例4: TestToBytes
public void TestToBytes()
{
byte[] bytes = new byte[] {0x02, 0x02, 0x96, 0xB5};
Integer32 test = new Integer32(-26955);
Assert.AreEqual(bytes, test.ToBytes());
Assert.AreEqual(new byte[] {0x02, 0x02, 0x00, 0xFF}, new Integer32(255).ToBytes());
Assert.AreEqual(6, new Integer32(2147483647).ToBytes().Length);
}
示例5: TestToBytes2
public void TestToBytes2()
{
Integer32 i = new Integer32(-1);
Assert.AreEqual(new byte[] {0x02, 0x01, 0xFF}, i.ToBytes());
}