本文整理汇总了C#中LinkedQueue.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# LinkedQueue.ToArray方法的具体用法?C# LinkedQueue.ToArray怎么用?C# LinkedQueue.ToArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedQueue
的用法示例。
在下文中一共展示了LinkedQueue.ToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
var test = new LinkedQueue<int>();
test.Enqueue(1);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Enqueue(2);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Enqueue(3);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Enqueue(4);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Enqueue(5);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Enqueue(6);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Enqueue(7);
Console.WriteLine(string.Join(" ", test.ToArray()));
Console.WriteLine("The queue count: {0}", test.Count);
test.Dequeue();
test.Dequeue();
Console.WriteLine(string.Join(" ", test.ToArray()));
Console.WriteLine("The queue count: {0}", test.Count);
Console.WriteLine(test.Peek());
Console.WriteLine(string.Join(" ", test.ToArray()));
Console.WriteLine("The queue count: {0}", test.Count);
test.Clear();
Console.WriteLine(string.Join(" ", test.ToArray()));
Console.WriteLine("The queue count: {0}", test.Count);
//test.Dequeue(); //if uncommented this line should throw exception
}
示例2: Main
static void Main()
{
try
{
LinkedQueue<string> queue = new LinkedQueue<string>();
queue.Enqueue("Message One");
queue.Enqueue("Message Two");
queue.Enqueue("Message Three");
queue.Enqueue("Message Four");
Console.WriteLine(queue.Peek());
Console.WriteLine(queue.Contains("Message Three"));
var array = queue.ToArray();
Console.WriteLine(string.Join(", ", array));
while (queue.Count > 0)
{
string message = queue.Dequeue();
Console.WriteLine(message);
}
queue.Dequeue();
}
catch (IndexOutOfRangeException iex)
{
Console.WriteLine(iex.TargetSite + " -> " + iex.Message);
}
catch (NullReferenceException nex)
{
Console.WriteLine(nex.TargetSite + " -> " + nex.Message);
}
}
示例3: Main
static void Main()
{
LinkedQueue<int> collection = new LinkedQueue<int>();
collection.Enqueue(1);
collection.Enqueue(2);
collection.Enqueue(3);
collection.Enqueue(4);
collection.Enqueue(5);
collection.Enqueue(6);
collection.Enqueue(7);
collection.Enqueue(8);
collection.Enqueue(9);
Console.WriteLine("Total elements: " + collection.Count);
Console.WriteLine(collection.Dequeue());
Console.WriteLine(collection.Dequeue());
Console.WriteLine(collection.Dequeue());
Console.WriteLine(collection.Dequeue());
Console.WriteLine("Total elements: " + collection.Count);
collection.Enqueue(10);
collection.Enqueue(11);
Console.WriteLine(collection.Dequeue());
Console.WriteLine("Total elements: " + collection.Count);
var array = collection.ToArray();
Console.WriteLine(string.Join(", ", array));
}
示例4: TestEmptyQueueToArray
public void TestEmptyQueueToArray()
{
var queue = new LinkedQueue<DateTime>();
DateTime[] array = queue.ToArray();
Assert.AreEqual(0, array.Length);
}
示例5: TestEmptyStackToArray_ShouldReturnEmptyArray
public void TestEmptyStackToArray_ShouldReturnEmptyArray()
{
var stack = new LinkedQueue<DateTime>();
var array = stack.ToArray();
var expected = new DateTime[0];
CollectionAssert.AreEqual(expected, array);
}
示例6: TestEmptyQueueToArray_ShouldReturnEmptyArray
public void TestEmptyQueueToArray_ShouldReturnEmptyArray()
{
var linkedQueue = new LinkedQueue<int>();
var queueToArray = linkedQueue.ToArray();
Assert.AreEqual(0, queueToArray.Length);
}
示例7: Main
/*
* Implement the ADT queue as dynamic linked list.
* Use generics (LinkedQueue<T>) to allow storing different data types in the queue.
*/
static void Main(string[] args)
{
ILinkedQueue<int> sample = new LinkedQueue<int>();
sample.Enqueue(1);
sample.Enqueue(2);
sample.Enqueue(3);
int[] sampleAsArray = sample.ToArray();
Console.WriteLine("Queue as array:");
for (int index = 0; index < sampleAsArray.Length; index++)
{
Console.WriteLine(sampleAsArray[index]);
}
Console.WriteLine("Dequeue + Peek");
Console.WriteLine(sample.Dequeue() + " Dequeue");
Console.WriteLine(sample.Dequeue() + " Dequeue");
Console.WriteLine(sample.Peek() + " Peek");
Console.WriteLine(sample.Dequeue() + " Dequeue");
sample.Enqueue(4);
Console.WriteLine("Does Contains 4? " + sample.Contains(4));
sample.Enqueue(5);
sample.Enqueue(6);
sample.Clear();
Console.WriteLine("Count after clear: " + sample.Count);
// Console.WriteLine(sample.Dequeue()); // exception expected
}
示例8: Main
private static void Main(string[] args)
{
var myQueue = new LinkedQueue<int>();
myQueue.Enqueue(1);
myQueue.Enqueue(2);
myQueue.Enqueue(3);
foreach (var val in myQueue)
{
Console.WriteLine(val);
}
Console.WriteLine("------------------------");
var num = myQueue.Dequeue();
Console.WriteLine("Dequeued value: " + num);
Console.WriteLine("------------------------");
foreach (var val in myQueue)
{
Console.WriteLine(val);
}
var arr = myQueue.ToArray();
Console.WriteLine("To Array:\n" + string.Join(",", arr));
myQueue.Clear();
Console.WriteLine("-------------Cleared-------------");
myQueue.Enqueue(5);
myQueue.Enqueue(6);
myQueue.Enqueue(7);
myQueue.Enqueue(8);
foreach (var val in myQueue)
{
Console.WriteLine(val);
}
}
示例9: ToArrayOnEmptyQueueShouldReturnEmptyArray
public void ToArrayOnEmptyQueueShouldReturnEmptyArray()
{
LinkedQueue<int> stack = new LinkedQueue<int>();
var resultArray = stack.ToArray();
Assert.AreEqual(0, resultArray.Length);
}
示例10: EmptyLinkedQueueToArray
public void EmptyLinkedQueueToArray()
{
var linkedQueue = new LinkedQueue<DateTime>();
var testArr = new DateTime[0];
CollectionAssert.AreEqual(testArr, linkedQueue.ToArray());
}
示例11: ConvertEmptyQueueToArray
public void ConvertEmptyQueueToArray()
{
LinkedQueue<int> queue = new LinkedQueue<int>();
int[] expected = new int[0];
int[] actual = queue.ToArray();
CollectionAssert.AreEqual(expected, actual);
}
示例12: To_Array_Empty
public void To_Array_Empty()
{
var dates = new LinkedQueue<DateTime>();
var arrTest = new DateTime[0];
CollectionAssert.AreEqual(arrTest, dates.ToArray());
}
示例13: LinkedQueueOfDatesToArrayShouldReturnEmptyArray
public void LinkedQueueOfDatesToArrayShouldReturnEmptyArray()
{
LinkedQueue<DateTime> linkedQueueDateTime = new LinkedQueue<DateTime>();
int[] expected = { };
DateTime[] result = linkedQueueDateTime.ToArray();
CollectionAssert.AreEqual(expected, result);
}
示例14: Main
static void Main(string[] args)
{
var linkedQueue = new LinkedQueue<int>();
linkedQueue.Dequeue();
linkedQueue.Enqueue(5);
linkedQueue.Enqueue(6);
linkedQueue.Enqueue(7);
Console.WriteLine(string.Join(" ",linkedQueue.ToArray()));
}
示例15: To_Array
public void To_Array()
{
var nums = new LinkedQueue<int>();
nums.Enqueue(3);
nums.Enqueue(5);
nums.Enqueue(-2);
nums.Enqueue(7);
int[] arrTest = { 3, 5, -2, 7 };
CollectionAssert.AreEqual(arrTest, nums.ToArray());
}