本文整理汇总了C#中Byte类的典型用法代码示例。如果您正苦于以下问题:C# Byte类的具体用法?C# Byte怎么用?C# Byte使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Byte类属于命名空间,在下文中一共展示了Byte类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadWriteAsyncParams
public ReadWriteAsyncParams(Byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
this.Buffer = buffer;
this.Offset = offset;
this.Count = count;
this.CancellationHelper = cancellationToken.CanBeCanceled ? new IOCancellationHelper(cancellationToken) : null;
}
示例2: WrapUnderlyingBytes
public void WrapUnderlyingBytes()
{
var rawBytes = new Byte[0];
var bytes = new Binary(rawBytes);
Assert.Same(rawBytes, (Byte[])bytes);
}
示例3: CopiesResult
public void CopiesResult()
{
// Note that a preable is not expected on the generated stream.
string text = "Hello world";
Byte[] textInBytes = Encoding.UTF8.GetBytes(text);
string outputText;
Byte[] buffer = new Byte[1024];
using (MemoryStream stream = new MemoryStream(buffer))
using (StringWriter writer = new StringWriter())
using (StreamWriter outputWriter = new StreamWriter(stream))
{
writer.Write(text);
writer.CopyTo(outputWriter);
outputText = writer.ToString();
}
Assert.Equal(text, outputText, StringComparer.Ordinal);
for (int i = 0; i < textInBytes.Length; i++)
{
Assert.Equal(textInBytes[i], buffer[i]);
}
}
示例4: DecompressArray
public static Byte[] DecompressArray(Byte[] inBuf)
{
Logger.Enter();
MemoryStream memory = new MemoryStream();
try
{
using (GZipStream stream = new GZipStream(new MemoryStream(inBuf), CompressionMode.Decompress))
{
const int size = 4096;
byte[] buffer = new byte[size];
int count = 0;
do
{
count = stream.Read(buffer, 0, size);
if (count > 0)
{
memory.Write(buffer, 0, count);
}
}
while (count > 0);
}
}
catch(Exception ex)
{
Logger.Error(String.Format("Decompress error.Internal msg: {0}", ex.Message));
}
Logger.Leave();
return memory.ToArray();
}
示例5: Decrement
public void Decrement()
{
// Reduce the size of the byte by 1 (note that this does not check for overflows!)
Byte b = new Byte(1);
b.TwosComplement();
RippleAdd(b);
}
示例6: OnlyUsesBufferUpToSize
public void OnlyUsesBufferUpToSize(int count)
{
string text = new string('a', count);
Byte[] textInBytes = Encoding.UTF8.GetBytes(text);
Mock<StreamWriter> mock;
Byte[] buffer = new Byte[textInBytes.Length + 100];
using (MemoryStream stream = new MemoryStream(buffer))
{
StringWriter writer = new StringWriter();
mock = new Mock<StreamWriter>(MockBehavior.Strict, stream) { CallBase = true };
mock.Setup(sw => sw.Write(It.IsAny<char[]>(),
It.IsAny<int>(),
It.Is<int>(c => c == StringWriterExtensions.BufferSize ||
c == textInBytes.Length % StringWriterExtensions.BufferSize)))
.Verifiable();
StreamWriter outputWriter = mock.Object;
writer.Write(text);
writer.CopyTo(outputWriter);
mock.Verify();
}
}
示例7: DecompressString
public static string DecompressString(Byte[] value)
{
if (value.Length > 0)
return Encoding.UTF8.GetString(CLZF.Decompress(value));
else
return "";
}
示例8: PosTest2
public void PosTest2()
{
Byte[] bytes = new Byte[] { };
UTF7Encoding UTF7 = new UTF7Encoding();
int charCount = UTF7.GetCharCount(bytes, 0, 0);
Assert.Equal(0, charCount);
}
示例9: CanCompareToBoxedRawBytes
public void CanCompareToBoxedRawBytes()
{
var lhs = new Binary(new Byte[] { 1, 2, 3 });
var rhs = new Byte[] { 1, 2, 3 };
Assert.Equal(0, lhs.CompareTo((Object)rhs));
}
示例10: ToggleBit
public void ToggleBit(byte register, int bit_position)
{
Byte b = new Byte(Read(register)); // Read control register
b.ToggleBit(bit_position); // Modify oscillator bit
// Write new byte value
Write(register, b.ToByte());
}
示例11: ModifyBaseStream
public async Task ModifyBaseStream()
{
var ms = await LocalMemoryStream.readAppFileAsync(gzTestFile("GZTestDocument.txt.gz"));
var zip = new GZipStream(ms, CompressionMode.Decompress);
int size = 1024;
Byte[] bytes = new Byte[size];
zip.BaseStream.Read(bytes, 0, size); // This will throw if the underlying stream is not writeable as expected
}
示例12: PosTest3
public void PosTest3()
{
UnicodeEncoding uE = new UnicodeEncoding(false, true);
Byte[] expectedValue = new Byte[] { 0xff, 0xfe };
Byte[] actualValue;
actualValue = uE.GetPreamble();
Assert.Equal(expectedValue, actualValue);
}
示例13: PosTest1
public void PosTest1()
{
Byte[] bytes = new Byte[] {
85, 84, 70, 56, 32, 69, 110,
99, 111, 100, 105, 110, 103, 32,
69, 120, 97, 109, 112, 108, 101};
UTF7Encoding utf7 = new UTF7Encoding();
string str = utf7.GetString(bytes, 0, bytes.Length);
}
示例14: GAPScanResponseEventArgs
public GAPScanResponseEventArgs(Byte rssi, Byte packet_type, Byte[] bd_addr, Byte address_type, Byte bond, Byte[] data)
{
this.rssi = rssi;
this.packet_type = packet_type;
this.bd_addr = bd_addr;
this.address_type = address_type;
this.bond = bond;
this.data = data;
}
示例15: PosTest3
public void PosTest3()
{
Char[] chars = GetCharArray(10);
Byte[] bytes = new Byte[20];
UnicodeEncoding uEncoding = new UnicodeEncoding();
int actualValue;
actualValue = uEncoding.GetBytes(chars, 0, 0, bytes, 20);
Assert.Equal(0, actualValue);
}