本文整理汇总了C#中Queue.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.CopyTo方法的具体用法?C# Queue.CopyTo怎么用?C# Queue.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Queue
的用法示例。
在下文中一共展示了Queue.CopyTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1: Test whether CopyTo(T[],System.Int32) is successful when System.Int32 is zero.");
try
{
Queue<string> TestQueue = new Queue<string>();
TestQueue.Enqueue("one");
TestQueue.Enqueue("two");
string[] TestArray = { "first", "second", "third", "fourth" };
TestQueue.CopyTo(TestArray, 0);
if (TestArray[0] != "one" || TestArray[1] != "two" || TestArray[2] != "third"
|| TestArray[3] != "fourth" || TestArray.GetLength(0) != 4)
{
TestLibrary.TestFramework.LogError("P01.1", "CopyTo(T[],System.Int32) failed when System.Int32 is zero!");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("P01.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogVerbose(e.StackTrace);
retVal = false;
}
return retVal;
}
示例2: Main
static void Main(string[] args)
{
//a queue for the locations that will be used to establish all available roads (a complete graph)
var locQ = new Queue<Location>(5);
//create the locations(vertexes), and queue them ...
locQ.Enqueue(new Location("Derby", 52.9230, -1.480));
locQ.Enqueue(new Location("Nottingham", 52.9546, -1.163));
locQ.Enqueue(new Location("Manchester", 53.4750, -2.252));
locQ.Enqueue(new Location("Sheffield", 53.378, -1.468));
locQ.Enqueue(new Location("Reading", 51.444, -0.989));
//create an array to reference all locations as we establish roads
var locs = new Location[5];
locQ.CopyTo(locs, 0);
//to store the roads we need to look up
var roads = new List<Road>();
//prepare the first location
var current = locQ.Dequeue();
while (current != null)
{
for (int i = locs.Length - 1; i >= 0; i--)
{
if (current != locs[i])
{
var road = new Road()
{
From = current,
To = locs[i]
};
if (roads.Contains(road) == false)
{
roads.Add(road);
Console.WriteLine("Adding {0} to {1}", road.From.Name, road.To.Name);
}
}
}
current = locQ.Count > 0 ? locQ.Dequeue() : null;
}
Console.WriteLine("There are {0} roads", roads.Count);
//calculate shortest route between...
var satNav = new RouteCalculator(roads);
satNav.AddDestination(locs[1]);
satNav.AddDestination(locs[2]);
satNav.AddDestination(locs[3]);
var route = satNav.CalculateShortestRoute(locs[0]);
foreach (var place in route)
{
Console.WriteLine(place.Name);
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
示例3: CopyTo_Array_CopiesItemsToArray
public void CopyTo_Array_CopiesItemsToArray()
{
var que = new Queue<string>();
que.Enqueue("foo");
var array = new string[1];
que.CopyTo(array, 0);
array.ShouldEqual(new []{"foo"});
}
示例4: Push_5_Integers
public void Push_5_Integers()
{
var expected = new int[] { 0, 1, 2, 3, 4 };
Queue<int> queue = new Queue<int>();
for (var i = 0; i < 5; i++)
{
queue.Push(i);
}
var actual = new int[5];
queue.CopyTo(actual, 0);
CollectionAssert.AreEqual(expected, actual);
}
示例5: NegTest2
public bool NegTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("NegTest2: ArgumentOutOfRangeException should be thrown when index is less than zero.");
try
{
Queue<string> TestQueue = new Queue<string>();
TestQueue.Enqueue("one");
TestQueue.Enqueue("two");
string[] TestArray = { "first", "second", "", "" };
TestQueue.CopyTo(TestArray, -1);
TestLibrary.TestFramework.LogError("N02.1", "ArgumentOutOfRangeException is not thrown when index is less than zero!");
retVal = false;
}
catch (ArgumentOutOfRangeException)
{
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("N02.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogVerbose(e.StackTrace);
retVal = false;
}
return retVal;
}
示例6: NegTest1
public bool NegTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("NegTest1: ArgumentNullException should be thrown when array is a null reference.");
try
{
Queue<string> TestQueue = new Queue<string>();
TestQueue.Enqueue("one");
TestQueue.Enqueue("two");
string[] TestArray = null;
TestQueue.CopyTo(TestArray, 0);
TestLibrary.TestFramework.LogError("N01.1", "ArgumentNullException is not thrown when array is a null reference!");
retVal = false;
}
catch (ArgumentNullException)
{
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("N01.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogVerbose(e.StackTrace);
retVal = false;
}
return retVal;
}
示例7: execTest3
public void execTest3()
{
DTEOperationAccessor.ToExec target = new DTEOperationAccessor.ToExec(2);
Queue<DTEOperation.DTEPrepared> commands = new Queue<DTEOperation.DTEPrepared>();
commands.Enqueue(new DTEOperation.DTEPrepared("Build.Cancel", ""));
commands.Enqueue(new DTEOperation.DTEPrepared("File.OpenProject", "app.sln"));
commands.Enqueue(new DTEOperation.DTEPrepared("Debug.Start", ""));
commands.Enqueue(new DTEOperation.DTEPrepared("Debug.StartWithoutDebugging", ""));
DTEOperation.DTEPrepared[] expected = new DTEOperation.DTEPrepared[commands.Count];
commands.CopyTo(expected, 0);
try {
target.exec(commands, true);
}
catch(ComponentException) {
// other type should fail the current test
}
Queue<DTEOperation.DTEPrepared> actual = target.getExecuted();
Assert.IsTrue(actual.Count != expected.Length);
Assert.IsTrue(actual.Count == 2);
int idx = 0;
foreach(DTEOperation.DTEPrepared obj in actual) {
Assert.AreEqual(expected[idx++], obj);
}
}
示例8: CopyTo_DequeueThenEnqueue
public static void CopyTo_DequeueThenEnqueue()
{
var queue1 = new Queue(100);
// Insert 50 items in the Queue
for (int i = 0; i < 50; i++)
{
queue1.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++)
{
queue1.Enqueue(i + 50);
queue1.Dequeue();
}
var array = new object[queue1.Count];
queue1.CopyTo(array, 0);
Assert.Equal(queue1.Count, array.Length);
for (int i = 0; i < queue1.Count; i++)
{
Assert.Equal(queue1.Dequeue(), array[i]);
}
}
示例9: Queue
private static void Queue()
{
// Queue
Queue<int> queue = new Queue<int>();
// add
queue.Enqueue(5);
// peek
int peek = queue.Peek();
//remove first
int first = queue.Dequeue();
//count
int count = queue.Count;
// find
bool exist = queue.Contains(5);
// copy to array
int[] copy = new int[100];
queue.CopyTo(copy, 0);
// convert it to array
copy = queue.ToArray();
}
示例10: actionFetchResults
public static string[] actionFetchResults(Select select, Authentication auth,
int num, int numStart, int numStartMin, int numEndMin)
{
log(timestamp() + " Beginning request to fetch billing results from the last "
+ wrapValue("" + num) + " days, starting from " + wrapValue("" + numStart)
+ " day(s) ago, " + wrapValue("" + numStartMin) + " minutes before current minute."
+ " ending " + wrapValue("" + numEndMin) + " minutes before current minute.");
Queue<string> soapIdQ = new Queue<string>();
String soapId = null;
// read next_start from database, set from last call
DateTime start = load_next_start();
if (default(DateTime) == start) // if next_start not set in db, intialize here...
{
start = DateTime.Today.AddDays(-1); // yesterday
log("SEL002_FetchSelect: Initializing " + dateString("next_start", start) + "\n");
}
DateTime end = DateTime.Now; // now
start.AddMinutes(-numStartMin);
start.AddDays(-numStart);
start.AddDays(-num);
if (0 == numEndMin) numEndMin = numStartMin;
end.AddMinutes(-numEndMin);
end.AddDays(-numStart);
int pageSize = 100;
int page = 0;
bool bFail = true;
int numTimeouts = 0;
int nRecords = 0;
int nTotalRecords = 0;
do {
nTotalRecords += nRecords;
do {
try {
nRecords = fetchResults(select, auth, start, end, pageSize, page, out soapId);
soapIdQ.Enqueue(soapId);
bFail = false;
} catch (Exception e) {
log(e);
bFail = true;
int msec = 900000;
log(timestamp() + " [" + numTimeouts++ + "]: Wait " + msec / 60000 + " minutes for initial query to finish: ");
pause(msec);
}
} while ( bFail );
page++;
} while ( nRecords > 0 );
log(timestamp() + " Completed request to fetch billing results from the last "
+ wrapValue("" + num)
+ " days, starting from " + wrapValue("" + numStart) + " day(s) ago, "
+ wrapValue("" + numStartMin) + " minutes before current minute.");
log("numTimeouts=" + numTimeouts);
log("nTotalRecords=" + nTotalRecords);
log("Number of pages=" + page);
log("Page Size=" + pageSize);
string[] soapIds = new string[soapIdQ.Count];
soapIdQ.CopyTo(soapIds, 0);
return soapIds;
}
示例11: getZweck
private string[] getZweck(Rectangle r)
{
string[] res = new string[14];
Rectangle v = new Rectangle(0, r.Y, 900, r.Height);
ocr.SetVariable("tessedit_char_whitelist", "\0");
Queue<String> tmp=new Queue<string>(getOCR(cropImg(v)).Split(Environment.NewLine.ToCharArray()));
if (tmp.ElementAt(0).StartsWith("Buchungsdatum"))
{
tmp.Dequeue();
}
if (tmp.Count > 14)
{
return res;
}
tmp.CopyTo(res, 0);
return res;
}
示例12: ICollection_CopyTo_ArgumentExceptions
public void ICollection_CopyTo_ArgumentExceptions()
{
ICollection ic = new Queue<int>(Enumerable.Range(0, 5));
Assert.Throws<ArgumentNullException>("array", () => ic.CopyTo(null, 0));
Assert.Throws<ArgumentException>(() => ic.CopyTo(new int[5, 5], 0));
Assert.Throws<ArgumentException>(() => ic.CopyTo(Array.CreateInstance(typeof(int), new[] { 10 }, new[] { 3 }), 0));
Assert.Throws<ArgumentOutOfRangeException>("index", () => ic.CopyTo(new int[10], -1));
Assert.Throws<ArgumentOutOfRangeException>("index", () => ic.CopyTo(new int[10], 11));
Assert.Throws<ArgumentException>(() => ic.CopyTo(new int[10], 7));
Assert.Throws<ArgumentException>(() => ic.CopyTo(new string[10], 0));
}
示例13: CopyTo_ArgumentValidation
public void CopyTo_ArgumentValidation()
{
// Argument validation
var q = new Queue<int>(Enumerable.Range(0, 4));
Assert.Throws<ArgumentNullException>("array", () => q.CopyTo(null, 0));
Assert.Throws<ArgumentOutOfRangeException>("arrayIndex", () => q.CopyTo(new int[4], -1));
Assert.Throws<ArgumentOutOfRangeException>("arrayIndex", () => q.CopyTo(new int[4], 5));
Assert.Throws<ArgumentException>(() => q.CopyTo(new int[4], 1));
}
示例14: CopyTo_Wrapped
public void CopyTo_Wrapped()
{
// Create a queue whose head has wrapped around
var q = new Queue<int>(4);
for (int i = 0; i < 4; i++)
{
q.Enqueue(i);
}
Assert.Equal(0, q.Dequeue());
Assert.Equal(1, q.Dequeue());
Assert.Equal(2, q.Count);
q.Enqueue(4);
q.Enqueue(5);
Assert.Equal(4, q.Count);
// Now copy; should require two copies under the covers
int[] arr = new int[4];
q.CopyTo(arr, 0);
for (int i = 0; i < 4; i++)
{
Assert.Equal(i + 2, arr[i]);
}
}
示例15: CopyTo_Normal
public void CopyTo_Normal()
{
var q = new Queue<int>();
// Copy an empty queue
var arr = new int[0];
q.CopyTo(arr, 0);
// Fill the queue
q = new Queue<int>(Enumerable.Range(0, 10));
arr = new int[q.Count];
// Copy the queue's elements to an array
q.CopyTo(arr, 0);
for (int i = 0; i < 10; i++)
{
Assert.Equal(i, arr[i]);
}
// Dequeue some elements
for (int i = 0; i < 3; i++)
{
Assert.Equal(i, q.Dequeue());
}
// Copy the remaining ones to a different location
q.CopyTo(arr, 1);
Assert.Equal(0, arr[0]);
for (int i = 1; i < 8; i++)
{
Assert.Equal(i + 2, arr[i]);
}
for (int i = 8; i < 10; i++)
{
Assert.Equal(i, arr[i]);
}
}