本文整理汇总了C#中ASCIIEncoding.GetByteCount方法的典型用法代码示例。如果您正苦于以下问题:C# ASCIIEncoding.GetByteCount方法的具体用法?C# ASCIIEncoding.GetByteCount怎么用?C# ASCIIEncoding.GetByteCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ASCIIEncoding
的用法示例。
在下文中一共展示了ASCIIEncoding.GetByteCount方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoPosTest
private void DoPosTest(string source, int expectedValue)
{
ASCIIEncoding ascii;
int actualValue;
ascii = new ASCIIEncoding();
actualValue = ascii.GetByteCount(source);
Assert.Equal(expectedValue, actualValue);
}
示例2: DoPosTest
private void DoPosTest(char[] chars, int startIndex, int count, int expectedValue)
{
ASCIIEncoding ascii;
int actualValue;
ascii = new ASCIIEncoding();
actualValue = ascii.GetByteCount(chars, startIndex, count);
Assert.Equal(expectedValue, actualValue);
}
示例3: NegTest1
public void NegTest1()
{
ASCIIEncoding ascii;
string source = null;
ascii = new ASCIIEncoding();
Assert.Throws<ArgumentNullException>(() =>
{
ascii.GetByteCount(source);
});
}
示例4: NegTest1
public void NegTest1()
{
ASCIIEncoding ascii;
char[] chars = null;
ascii = new ASCIIEncoding();
Assert.Throws<ArgumentNullException>(() =>
{
ascii.GetByteCount(chars, 0, 0);
});
}
示例5: PosTest2
public void PosTest2()
{
ASCIIEncoding ascii;
byte[] bytes;
int byteIndex, byteCount;
char[] chars;
int charIndex;
string source;
ascii = new ASCIIEncoding();
source = _generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH);
bytes = new byte[ascii.GetByteCount(source)];
ascii.GetBytes(source, 0, source.Length, bytes, 0);
byteIndex = _generator.GetInt32(-55) % bytes.Length;
byteCount = _generator.GetInt32(-55) % (bytes.Length - byteIndex) + 1;
chars = new char[byteCount + _generator.GetInt32(-55) % c_MAX_STRING_LENGTH];
charIndex = _generator.GetInt32(-55) % (chars.Length - byteCount + 1);
DoPosTest(ascii, bytes, byteIndex, byteCount, chars, charIndex);
}
示例6: PosTest2
public void PosTest2()
{
ASCIIEncoding ascii;
char[] chars;
int charIndex, count;
byte[] bytes;
int byteIndex;
ascii = new ASCIIEncoding();
InitializeCharacterArray(out chars);
charIndex = _generator.GetInt32(-55) % chars.Length;
count = _generator.GetInt32(-55) % (chars.Length - charIndex) + 1;
int minLength = ascii.GetByteCount(chars, charIndex, count);
int length = minLength + _generator.GetInt32(-55) % (Int16.MaxValue - minLength);
bytes = new byte[length];
for (int i = 0; i < bytes.Length; ++i)
{
bytes[i] = 0;
}
byteIndex = _generator.GetInt32(-55) % (bytes.Length - minLength + 1);
DoPosTest(ascii, chars, charIndex, count, bytes, byteIndex);
}
示例7: PosTest2
public void PosTest2()
{
ASCIIEncoding ascii;
string source;
int charIndex, count;
byte[] bytes;
int byteIndex;
ascii = new ASCIIEncoding();
source = _generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH);
charIndex = _generator.GetInt32(-55) % source.Length;
count = _generator.GetInt32(-55) % (source.Length - charIndex) + 1;
int minLength = ascii.GetByteCount(source.Substring(charIndex, count));
int length = minLength + _generator.GetInt32(-55) % (Int16.MaxValue - minLength);
bytes = new byte[length];
for (int i = 0; i < bytes.Length; ++i)
{
bytes[i] = 0;
}
byteIndex = _generator.GetInt32(-55) % (bytes.Length - minLength + 1);
DoPosTest(ascii, source, charIndex, count, bytes, byteIndex);
}
示例8: DoNegAOORTest
private void DoNegAOORTest(char[] chars, int startIndex, int count)
{
ASCIIEncoding ascii = new ASCIIEncoding();
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
ascii.GetByteCount(chars, startIndex, count);
});
}
示例9: NegTest8
public void NegTest8()
{
ASCIIEncoding ascii;
char[] chars;
int charIndex, count;
byte[] bytes;
int byteIndex;
ascii = new ASCIIEncoding();
InitializeCharacterArray(out chars);
charIndex = _generator.GetInt32(-55) % chars.Length;
count = _generator.GetInt32(-55) % (chars.Length - charIndex) + 1;
int minLength = ascii.GetByteCount(chars, charIndex, count);
bytes = new byte[_generator.GetInt32(-55) % minLength];
byteIndex = 0;
Assert.Throws<ArgumentException>(() =>
{
ascii.GetBytes(chars, charIndex, count, bytes, byteIndex);
});
}
示例10: NegTest7
public void NegTest7()
{
ASCIIEncoding ascii;
char[] chars;
int charIndex, count;
byte[] bytes;
int byteIndex;
ascii = new ASCIIEncoding();
InitializeCharacterArray(out chars);
charIndex = _generator.GetInt32(-55) % chars.Length;
count = _generator.GetInt32(-55) % (chars.Length - charIndex) + 1;
int minLength = ascii.GetByteCount(chars, charIndex, count);
bytes = new byte[minLength];
byteIndex = bytes.Length + _generator.GetInt32(-55) % (int.MaxValue - bytes.Length);
DoNegAOORTest(ascii, chars, charIndex, count, bytes, byteIndex);
}
示例11: NegTest8
public void NegTest8()
{
ASCIIEncoding ascii;
string source;
int charIndex, count;
byte[] bytes;
int byteIndex;
ascii = new ASCIIEncoding();
source = _generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH);
charIndex = _generator.GetInt32(-55) % source.Length;
count = _generator.GetInt32(-55) % (source.Length - charIndex) + 1;
int minLength = ascii.GetByteCount(source.Substring(charIndex, count));
bytes = new byte[_generator.GetInt32(-55) % minLength];
byteIndex = 0;
Assert.Throws<ArgumentException>(() =>
{
ascii.GetBytes(source, charIndex, count, bytes, byteIndex);
});
}
示例12: NegTest7
public void NegTest7()
{
ASCIIEncoding ascii;
string source;
int charIndex, count;
byte[] bytes;
int byteIndex;
ascii = new ASCIIEncoding();
source = _generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH);
charIndex = _generator.GetInt32(-55) % source.Length;
count = _generator.GetInt32(-55) % (source.Length - charIndex) + 1;
int minLength = ascii.GetByteCount(source.Substring(charIndex, count));
bytes = new byte[minLength];
byteIndex = bytes.Length + _generator.GetInt32(-55) % (int.MaxValue - bytes.Length);
DoNegAOORTest(ascii, source, charIndex, count, bytes, byteIndex);
}