本文整理汇总了C#中System.Collections.Queue.TrimToSize方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.TrimToSize方法的具体用法?C# Queue.TrimToSize怎么用?C# Queue.TrimToSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Queue
的用法示例。
在下文中一共展示了Queue.TrimToSize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TrimToSize_Enqueue_Dequeue
public void TrimToSize_Enqueue_Dequeue ()
{
Queue queue = new Queue (32, 1.0F);
for (int i = 0; i < 31; i++)
queue.Enqueue (i);
queue.TrimToSize ();
queue.Enqueue (411);
Assert.AreEqual (32, queue.Count, "Count-1");
Assert.AreEqual (0, queue.Dequeue (), "0");
}
示例2: TrimToSize_Dequeue_Enqueue
public void TrimToSize_Dequeue_Enqueue ()
{
Queue queue = new Queue (32, 1.0F);
for (int i = 0; i < 31; i++)
queue.Enqueue (i);
queue.TrimToSize ();
Assert.AreEqual (0, queue.Dequeue (), "0");
queue.Enqueue (411);
Assert.AreEqual (31, queue.Count, "Count-1");
for (int i = 1; i < 31; i++) {
Assert.AreEqual (i, queue.Peek (), "Peek" + i.ToString ());
Assert.AreEqual (i, queue.Dequeue (), "Dequeue" + i.ToString ());
}
Assert.AreEqual (1, queue.Count, "Count-2");
Assert.AreEqual (411, queue.Dequeue (), "411");
}
示例3: getContents
private void getContents(string origFileName, string genFileName)
{
//compare the two files
xmlFileRdr = new XmlTextReader(origFileName);
origContentsQ = new Queue();
int testNo = 0;
//get the contents of the orignal file
while (xmlFileRdr.Read())
{
switch (xmlFileRdr.NodeType)
{
case XmlNodeType.Element:
{
switch (xmlFileRdr.Name)
{
case "Inject":
{
testNo++;
//information about fault, limit, or test
type = Convert.ToInt16(xmlFileRdr.GetAttribute("Type").ToString());
name = xmlFileRdr.GetAttribute("Name").ToString();
enabled = Convert.ToInt16(xmlFileRdr.GetAttribute("Enabled").ToString());
//create a new test case
TestCase newCase = new TestCase("", enabled, name, type, testNo);
origContentsQ.Enqueue(newCase);
break;
}
case "TestFile":
{
//start of the test file
Console.Out.WriteLine();
Console.Out.WriteLine("Purpose of this test is to [" + xmlFileRdr.GetAttribute("Purpose") + "]");
Console.Out.WriteLine("-----------------------------------------------------------------------");
Console.Out.WriteLine();
break;
}
}
break;
}
}
}
xmlFileRdr.Close();
origContentsQ.TrimToSize();
//get the contents of the generated file
xmlFileRdr = new XmlTextReader(genFileName);
genContentsQ = new Queue();
while (xmlFileRdr.Read())
{
switch (xmlFileRdr.NodeType)
{
case XmlNodeType.Element:
{
switch (xmlFileRdr.Name)
{
case "Inject":
{
testNo++;
//information about fault, limit, or test
type = Convert.ToInt16(xmlFileRdr.GetAttribute("Type").ToString());
name = xmlFileRdr.GetAttribute("Name").ToString();
enabled = Convert.ToInt16(xmlFileRdr.GetAttribute("Enabled").ToString());
//create a new test case
TestCase newCase = new TestCase("", enabled, name, type, testNo);
genContentsQ.Enqueue(newCase);
break;
}
}
break;
}
}
}
//close the file and make sure the queue is as small as it can be
xmlFileRdr.Close();
genContentsQ.TrimToSize();
//compare the two contents of the file
compare();
}
示例4: SetConfigValue
internal static void SetConfigValue(string key, int itemmax)
{
XmlDocument xmlDoc = new XmlDocument( );
xmlDoc.Load(Application.ExecutablePath + ".config");
//最多可以保存9个
Queue qu = new Queue(itemmax);
foreach (XmlElement xe in xmlDoc.SelectNodes("/configuration/mathWord"))
{
qu.Enqueue(xe.InnerText);
}
if (qu.Count > 9)
{
qu.Dequeue( );
qu.TrimToSize( );
}
//去除重复的.
if (!qu.Contains(key))
qu.Enqueue(key);
XmlNode root = xmlDoc.SelectSingleNode("configuration");
//主要是了保证不重复
root.RemoveAll( );
foreach (string str in qu)
{
XmlElement xElem = xmlDoc.CreateElement("mathWord");
xElem.InnerText = str;
root.AppendChild(xElem);
}
xmlDoc.Save(Application.ExecutablePath + ".config");
}
示例5: MergingAllImage
private Bitmap MergingAllImage()
{
Bitmap LastBitmap = new Bitmap(this.bitmap.Width, this.bitmap.Height);
using (Graphics grp = Graphics.FromImage(LastBitmap))
{
var DefaultBackgroundBrushes = Brushes.Black;
if (App.Default.IsBlackShadow)
{
DefaultBackgroundBrushes = Brushes.White;
}
grp.FillRectangle(
DefaultBackgroundBrushes, 0, 0, this.bitmap.Width, this.bitmap.Height);
}
Rectangle _Rectangle = new Rectangle(0, 0, LastBitmap.Width, LastBitmap.Height);
Queue TempQueue = new Queue();
LastBitmap.GaussianBlur(ref _Rectangle, App.Default.ShadowBlurRadio);
if(ImgQueue.Count > 0)
{
var canvas = Graphics.FromImage(LastBitmap);
while(ImgQueue.Count > 0)
{
Bitmap tmpImg=(Bitmap)ImgQueue.Dequeue();
if (App.Default.IsBlackShadow)
{
tmpImg.MakeTransparent(Color.White);
}
else
{
tmpImg.MakeTransparent(Color.Black);
}
tmpImg.GaussianBlur(ref _Rectangle,App.Default.ShadowBlurRadio);
if (ImgQueue.Count < ImgQueueLitmitation)
{
TempQueue.Enqueue(tmpImg);
}
ColorMatrix cm = new ColorMatrix();
cm.Matrix33 = App.Default.ShadowAlpha;
ImageAttributes _ImageAttributes = new ImageAttributes();
_ImageAttributes.SetColorMatrix(cm);
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
canvas.DrawImage(tmpImg, new Rectangle(0, 0, this.panelView.Size.Width, this.panelView.Size.Height),
0, 0, this.panelView.Size.Width, this.panelView.Size.Height,GraphicsUnit.Pixel,_ImageAttributes);
canvas.Save();
}
ImgQueue = TempQueue;
ImgQueue.TrimToSize();
}
return LastBitmap;
}