本文整理汇总了C#中Queue.TrimToSize方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.TrimToSize方法的具体用法?C# Queue.TrimToSize怎么用?C# Queue.TrimToSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.TrimToSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TrimToSizeTest
public void TrimToSizeTest()
{
var queue = new Queue(64);
Assert.AreEqual(0, queue.Count);
Assert.AreEqual(64, queue.Capacity);
queue.Enqueue("No.1");
queue.Enqueue("No.2");
Assert.AreEqual(2, queue.Count);
Assert.AreEqual(64, queue.Capacity);
queue.TrimToSize();
Assert.AreEqual(2, queue.Count);
Assert.AreEqual(2, queue.Capacity);
}
示例2: TrimToSize_Wrapped
public static void TrimToSize_Wrapped()
{
var queue = new Queue(100);
// Insert 50 items in the Queue
for (int i = 0; i < 50; i++)
{
queue.Enqueue(i);
}
// Insert and Remove 75 items in the Queue. This should wrap the queue
// where there is 25 at the end of the array and 25 at the beginning
for (int i = 0; i < 75; i++)
{
queue.Enqueue(i + 50);
queue.Dequeue();
}
queue.TrimToSize();
Assert.Equal(50, queue.Count);
Assert.Equal(75, queue.Dequeue());
queue.Enqueue(100);
Assert.Equal(50, queue.Count);
Assert.Equal(76, queue.Dequeue());
}
示例3: runTest
public bool runTest()
{
//////////// Global Variables used for all tests
String strValue = String.Empty;
int iCountErrors = 0;
int iCountTestcases = 0;
Queue que;
Object dequeuedValue;
try
{
///////////////////////// START TESTS ////////////////////////////
iCountTestcases++;
que = new Queue();
try
{
que.TrimToSize();
}
catch (Exception)
{
iCountErrors++;
}
que = new Queue();
for (int i = 0; i < 1000; i++)
{
que.Enqueue(i);
}
try
{
que.TrimToSize();
}
catch (Exception)
{
iCountErrors++;
}
que = new Queue(100000);
try
{
que.TrimToSize();
}
catch (Exception)
{
iCountErrors++;
}
//[]Empty Queue
iCountTestcases++;
que = new Queue();
que.TrimToSize();
if (que.Count != 0)
{
iCountErrors++;
}
que.Enqueue(100);
if ((int)(dequeuedValue = que.Dequeue()) != 100)
{
iCountErrors++;
}
//[]After Clear
iCountTestcases++;
que = new Queue();
// Insert 50 items in the Queue
for (int i = 0; i < 100; i++)
{
que.Enqueue(i);
}
que.Clear();
que.TrimToSize();
if (que.Count != 0)
{
iCountErrors++;
}
que.Enqueue(100);
if ((int)(dequeuedValue = que.Dequeue()) != 100)
{
iCountErrors++;
}
//[]After Dequeue all items
iCountTestcases++;
que = new Queue();
// Insert 50 items in the Queue
//.........这里部分代码省略.........
示例4: runTest
public bool runTest()
{
Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
String strLoc = "Loc_000oo";
String strValue = String.Empty;
int iCountErrors = 0;
int iCountTestcases = 0;
Queue que;
try
{
strLoc = "Loc_384sdg";
iCountTestcases++;
que = new Queue();
try
{
que.TrimToSize();
}
catch(Exception ex)
{
iCountErrors++;
Console.WriteLine("Err_3947sDG! unexpected exception thrown," + ex.GetType().Name);
}
que = new Queue();
for(int i=0; i<1000; i++)
{
que.Enqueue(i);
}
try
{
que.TrimToSize();
}
catch(Exception ex)
{
iCountErrors++;
Console.WriteLine("Err_3947sDG! unexpected exception thrown," + ex.GetType().Name);
}
que = new Queue(100000);
try
{
que.TrimToSize();
}
catch(Exception ex)
{
iCountErrors++;
Console.WriteLine("Err_3947sDG! unexpected exception thrown," + ex.GetType().Name);
}
}
catch (Exception exc_general )
{
++iCountErrors;
Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
}
if ( iCountErrors == 0 )
{
Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
return true;
}
else
{
Console.WriteLine("FAiL! "+s_strTFName+" ,inCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
return false;
}
}