本文整理汇总了C#中Queue.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.AddRange方法的具体用法?C# Queue.AddRange怎么用?C# Queue.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.AddRange方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAddRange
public void TestAddRange()
{
int[] expected = new int[4] { 0, 1, 2, 3 };
var q = new Queue<int>();
q.AddRange(expected);
Assert.AreEqual(expected.Length, q.Count);
Assert.AreEqual(expected[0], q.Peek());
}
示例2: TestEnumator
public void TestEnumator()
{
int[] expected = new int[4] { 0, 1, 2, 3 };
var q = new Queue<int>();
q.AddRange(expected);
int i = 0;
foreach (int item in q)
{
Assert.AreEqual(expected[i], item);
i++;
}
}
示例3: Main
static void Main(string[] args)
{
if(args == null || args.Length == 0)
{
Console.WriteLine("Please, specify the input file name as the first parameter");
Console.WriteLine("Please, specify the output file name as the second parameter (optional)");
Console.WriteLine("Please, specify the amount of beats as the third parameter (optional, 4 by default)");
return;
}
#endif
var allLengths = new Queue<int>();
var allNotes = new Queue<string>();
var carer = new ProcessorCarer();
carer.Register<DigitProcessor>();
carer.Register<NoteProcessor>();
using(var reader = new StreamReader(args[0]))
{
string line;
while((line = reader.ReadLine()) != null)
{
if(string.IsNullOrEmpty(line))
continue;
if(char.IsLetter(line[0]))
{
allNotes.AddRange(carer.Get<NoteProcessor>().Process(line));
}
else if(char.IsDigit(line[0]) || line.StartsWith("."))
{
allLengths.AddRange(carer.Get<DigitProcessor>().Process(line));
}
}
}
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
Stream outFile = null;
try
{
if(args.Length > 2)
{
outFile = File.Create(args[1]);
Trace.Listeners.Add(new TextWriterTraceListener(outFile));
}
Trace.Write("Notes:\n");
Trace.Write(string.Join(", ", allNotes));
Trace.Write("\nLengths: \n");
Trace.Write(string.Join(", ", allLengths));
}
finally
{
if(outFile != null)
outFile.Dispose();
}
Trace.Flush();
}
示例4: List
public Task<IEnumerable<Uri>> List(Uri path, bool recursive)
{
var items = new List<Uri>();
var queue = new Queue<StorageSimulatorItem>();
var pathInfo = new PathInfo(path);
this.AssertIsValidWabsUri(pathInfo);
StorageSimulatorItem item = this.GetItem(pathInfo, pathInfo.Path.IsNullOrEmpty());
if (item.IsNotNull())
{
queue.Enqueue(item);
while (queue.Count > 0)
{
item = queue.Remove();
queue.AddRange(item.Items.Values);
items.Add(item.Path);
}
}
return Task.FromResult((IEnumerable<Uri>)items);
}