本文整理汇总了C#中System.Collections.Queue.ToArray方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.ToArray方法的具体用法?C# Queue.ToArray怎么用?C# Queue.ToArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Queue
的用法示例。
在下文中一共展示了Queue.ToArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindType
private CodeElement FindType(ProjectItems projectItems, string typename)
{
var tokens = typename.Split('.');
var path =new Queue<string>(tokens.ToList());
while ( path.Count>0)
{
var itemName = path.Dequeue();
var found = false;
Debug.WriteLine("Searching for " + itemName );
if (projectItems == null) break;
foreach (ProjectItem projectItem in projectItems)
{
Debug.WriteLine("Checking " + projectItem.Name );
if (projectItem.Name.Equals(itemName, StringComparison.CurrentCultureIgnoreCase))
{
Debug.WriteLine("Found the project Item!!!");
found = true;
if (projectItem.ProjectItems != null && projectItem.ProjectItems.Count > 0)
{
Debug.WriteLine("Searching children");
// search the children of this projectitem
var foundHere = FindType(projectItem.ProjectItems, string.Join(".", path.ToArray()));
if (foundHere != null)
{
Debug.WriteLine("Found in children of " + projectItem.Name );
return foundHere;
}
Debug.WriteLine("Continuing looking");
break;
}
}
else
{
var theType = FindType(projectItem, typename);
if (theType != null)
{
Debug.WriteLine("Found it!!!!" + theType.FullName );
return theType;
}
}
}
if (!found)
{
Debug.WriteLine("Didnt find this token" + itemName );
break;
}
}
return null;
}
示例2: TrimQueueToTime
private void TrimQueueToTime(Queue<Sample> q, double secs)
{
while (SumTimes(new List<Sample>(q.ToArray())) > (secs+5)) {
Sample tmp = q.Dequeue();
}
}
示例3: containsCPlayerInfo
//Whether a move queue contains a given player
private bool containsCPlayerInfo(Queue<CPlayerInfo> queueList, String player)
{
CPlayerInfo[] playerArray = queueList.ToArray();
for (Int32 index = 0; index < queueList.Count; index++)
{
if (((CPlayerInfo)playerArray[index]).SoldierName.Equals(player))
{
return true;
}
}
return false;
}
示例4: CompleteAllOnDispose
void CompleteAllOnDispose (Queue queue)
{
object [] pending = queue.ToArray ();
queue.Clear ();
WaitCallback cb;
for (int i = 0; i < pending.Length; i++) {
SocketAsyncResult ares = (SocketAsyncResult) pending [i];
cb = new WaitCallback (ares.CompleteDisposed);
ThreadPool.QueueUserWorkItem (cb, null);
}
}
示例5: WriteReadData
public int WriteReadData(FindPacketSignature func, byte[] out_buffer, ref byte[] in_buffer, int out_length, int target_in_length, uint pos_count_data_size = 0, uint size_data = 0, uint header_size = 0)
{
int reading_size = 0;
using (TcpClient tcp = new TcpClient())
{
Queue<byte> reading_queue = new Queue<byte>(8192);
try
{
Thread.Sleep(m_delay_between_sending);
tcp.SendTimeout = 500;
tcp.ReceiveTimeout = 500;
IAsyncResult ar = tcp.BeginConnect(m_address, m_port, null, null);
using (WaitHandle wh = ar.AsyncWaitHandle)
{
if (!ar.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(10), false))
{
throw new TimeoutException();
}
else
{
if (tcp.Client.Connected)
{
tcp.Client.ReceiveTimeout = m_read_timeout;
tcp.Client.SendTimeout = m_write_timeout;
// посылка данных
if (tcp.Client.Send(out_buffer, out_length, SocketFlags.None) == out_length)
{
uint elapsed_time_count = 0;
Thread.Sleep(50);
// чтение данных
while (elapsed_time_count < m_read_timeout)
{
if (tcp.Client.Available > 0)
{
try
{
byte[] tmp_buff = new byte[tcp.Available];
int readed_bytes = tcp.Client.Receive(tmp_buff, 0, tmp_buff.Length, SocketFlags.None);
for (int i = 0; i < readed_bytes; i++)
{
reading_queue.Enqueue(tmp_buff[i]);
}
}
catch (Exception ex)
{
WriteToLog("Receive: " + ex.Message);
}
}
elapsed_time_count += 50;
Thread.Sleep(50);
}
int pos = -1;
if ((pos = func(reading_queue)) >= 0)
{
for (int i = 0; i < pos; i++)
{
reading_queue.Dequeue();
}
byte[] temp_buffer = new byte[reading_size = reading_queue.Count];
temp_buffer = reading_queue.ToArray();
if (target_in_length == 0)
{
if (reading_size > pos_count_data_size)
{
target_in_length = Convert.ToInt32(temp_buffer[pos_count_data_size] * size_data + header_size);
}
}
if (target_in_length > 0)
{
if (reading_size >= target_in_length)
{
reading_size = target_in_length;
for (int i = 0; i < target_in_length && i < in_buffer.Length; i++)
{
in_buffer[i] = temp_buffer[i];
}
}
}
}
}
}
}
}
}
catch (Exception ex)
{
WriteToLog(ex.Message);
return -1;
}
finally
//.........这里部分代码省略.........
示例6: GetEnumerator
public override IEnumerator<OtpActor.Continuation> GetEnumerator()
{
m_log.Info("[Distributed PC] New PCVM is ready: " + m_mbox.Self);
while (true)
{
OtpMsg msg = null;
yield return (delegate(OtpMsg received) { msg = received; });
OtpErlangObject obj = msg.getMsg();
if (obj is OtpErlangAtom)
{
string atom = ((OtpErlangAtom)obj).atomValue();
if (!String.IsNullOrEmpty(atom) && atom == "noconnection")
{
break;
}
}
OtpErlangPid sender = null;
OtpErlangObject[] reply = new OtpErlangObject[3];
try
{
OtpErlangTuple t = (OtpErlangTuple)obj;
sender = (OtpErlangPid)t.elementAt(0);
reply[0] = sender;
reply[1] = new OtpErlangAtom("ok");
string instr = ((OtpErlangAtom)t.elementAt(1)).ToString();
if (instr == "load")
{
Parser parser = PCVM.MakeParser();
string script = String.Empty;
if (t.elementAt(2) is OtpErlangString)
{
script = ((OtpErlangString)t.elementAt(2)).stringValue();
}
else
{
script = OtpErlangString.newString(((OtpErlangBinary)t.elementAt(2)).binaryValue());
}
bool debug = ((OtpErlangAtom)t.elementAt(3)).boolValue();
SYMBOL ast = parser.Parse(script);
m_vm.Call((Compiler.ExpPair)ast);
if (debug)
{
reply[2] = new OtpErlangAtom("continue");
}
else
{
Queue<PCObj> popped = new Queue<PCObj>();
try
{
m_vm.Finish(popped);
}
finally
{
reply = new OtpErlangObject[] {
reply[0],
reply[1],
new OtpErlangAtom("finished"),
ErlangObjectFromPCVMObject(popped.ToArray())
};
}
}
}
else if (instr == "step")
{
bool cont = true;
Queue<PCObj> popped = new Queue<PCObj>();
try
{
cont = m_vm.Step(popped);
}
finally
{
reply = new OtpErlangObject[] {
reply[0],
reply[1],
new OtpErlangAtom(cont ? "continue" : "finished"),
ErlangObjectFromPCVMObject(popped.ToArray())
};
}
}
else if (instr == "finish")
{
Queue<PCObj> popped = new Queue<PCObj>();
try
{
m_vm.Finish(popped);
}
finally
//.........这里部分代码省略.........
示例7: JoinOperandSymbols
private static void JoinOperandSymbols(Queue<string> queueOperand, Queue<string> queueTokens)
{
queueTokens.Enqueue(String.Join("", queueOperand.ToArray()));
queueOperand.Clear();
}
示例8: printStages
private static void printStages(Queue<CmdBase> stages, int cycle)
{
CmdBase[] array = stages.ToArray();
Console.WriteLine("=======================");
Console.WriteLine("Cycle: " + cycle);
foreach (CmdBase t in array)
{
Console.WriteLine(t);
}
}
示例9: GetCPlayerInfo
//Helper method to find a player's information in the move queue
private CPlayerInfo GetCPlayerInfo(Queue<CPlayerInfo> queueList, String player)
{
this.DebugWrite("Entering getCPlayerInfo", 7);
CPlayerInfo playerInfo = null;
try {
CPlayerInfo[] playerArray = queueList.ToArray();
for (Int32 index = 0; index < queueList.Count; index++) {
if (playerArray[index].SoldierName == player) {
playerInfo = playerArray[index];
}
}
}
catch (Exception e) {
this.HandleException(new AdKatsException("Error while getting player info from teamswap queue.", e));
}
this.DebugWrite("Exiting getCPlayerInfo", 7);
return playerInfo;
}
示例10: ContainsCPlayerInfo
//Whether a move queue contains a given player
private bool ContainsCPlayerInfo(Queue<CPlayerInfo> queueList, String player)
{
this.DebugWrite("Entering containsCPlayerInfo", 7);
try {
CPlayerInfo[] playerArray = queueList.ToArray();
for (Int32 index = 0; index < queueList.Count; index++) {
if (playerArray[index].SoldierName == player) {
return true;
}
}
return false;
}
catch (Exception e) {
this.HandleException(new AdKatsException("Error while checking for player in teamswap queue.", e));
}
this.DebugWrite("Exiting containsCPlayerInfo", 7);
return false;
}
示例11: IndexOfCPlayerInfo
//The index of a player in the move queue
private Int32 IndexOfCPlayerInfo(Queue<CPlayerInfo> queueList, String player)
{
this.DebugWrite("Entering getCPlayerInfo", 7);
try {
CPlayerInfo[] playerArray = queueList.ToArray();
for (Int32 i = 0; i < queueList.Count; i++) {
if (playerArray[i].SoldierName == player) {
return i;
}
}
}
catch (Exception e) {
this.HandleException(new AdKatsException("Error while getting index of player in teamswap queue.", e));
}
this.DebugWrite("Exiting getCPlayerInfo", 7);
return -1;
}
示例12: MakeLenOctets
/// <summary>
/// Rutina za razbijanje duljine u pripadne byteove
/// za LENGTH OCTETS.
///
/// FIXME: Ovo je vec sad obsolete...
/// </summary>
/// <param name="ulazLenNumber">uzimam da duljina moze
/// biti navise MaxInteger</param>
/// <returns>polje byteova, Length Octets za zadanu duljinu</returns>
public static byte[] MakeLenOctets(int ulazLenNumber)
{
/// za konkretnu duljinu postoje dva oblika:
/// short form i long form.
/// Short form pokriva duljine od 0..127,
/// Long form pokriva dovoljno velike brojeve..
if (ulazLenNumber < 128)
{
return new byte[]{Convert.ToByte(ulazLenNumber)};
}
else
{
// long form
// prvi oktet je broj dodatnih okteta za zapis,
// preostali daju duljinu u bazi 256, sa MostSig..
// bitom prvim.
int tmp = ulazLenNumber;
Queue q = new Queue();
int i=0;
while ((tmp & 0xff000000)==0)
{
tmp = tmp << 8;
i++;
}
while ( i<4 )
{
q.Enqueue( Convert.ToByte( (tmp & 0xff000000) >> 24 ) );
tmp = tmp << 8;
i++;
}
int len = q.ToArray().Length;
Byte[] tmpArray = new Byte[len+1];
tmpArray[0]=Convert.ToByte(len + 128);
for ( i=0; i < len; i++)
{
tmpArray[i+1] = (Byte)(q.Dequeue());
}
return ( tmpArray );
}
}
示例13: MakeTagOctets
/* -----------------------------------------------------*/
/// <summary>
/// Trebaju mi static fje koje barataju i rade sa
/// prebacivanjem tag i length integera u pripadajuce
/// oktete.
/// </summary>
/// <returns>Vraca odgovarajuce polje byte-va koje
/// sadrzi tag oktete</returns>
public static byte[] MakeTagOctets(int ulazTagNumber)
{
/// treba odrediti koliki je int.
/// Za ("tagnumber<32") dovoljan je prvi oktet,
/// (to je 5 raspolozivih bitova)
///
/// Za veci tagNumber prelazi se u highTagNumber
/// format.
if (ulazTagNumber < 0 )
{
throw new Exception("Nema negativnih tag numbera..");
}
if (ulazTagNumber < 0x1f)
{
return new byte[]{Convert.ToByte(ulazTagNumber)};
}
else
{ /// high tag number form
/// zapisan u bazi 128, pocevsi od drugog byte-a.
/// Prvi byte je oblika ???11111
/// Svi osim zadnjeg od drugog nadalje su oblika
/// 0???????
/// Zadnji je oblika
/// 1???????
///
/// Zasad pretpostavljam da je tag number MaxInt
Byte[] b = new Byte[5];
b[0] = Convert.ToByte((ulazTagNumber & 0x0000007f) | 0x80); // ovo je zadnji...
b[1] = Convert.ToByte((ulazTagNumber & 0x00003f80) >> 7);
b[2] = Convert.ToByte((ulazTagNumber & 0x001fb000) >> 14);
b[3] = Convert.ToByte((ulazTagNumber & 0x0fe00000) >> 21);
b[4] = Convert.ToByte((ulazTagNumber & 0xf0000000) >> 28);
Queue q = new Queue();
q.Enqueue((Byte)0x1f);
int i=4;
while (b[i]==0) i--;
while ( i >= 0 )
{
q.Enqueue( b[i] );
i--;
}
Byte[] tmpArray = new Byte[q.ToArray().Length];
for ( i=0; i< q.ToArray().Length; i++)
{
tmpArray[i] = (Byte)((q.ToArray())[i]);
}
return ( tmpArray );
}
}
示例14: GetPixelsForTargetPixel
SColor[] GetPixelsForTargetPixel(int _x, int _y)
{
Queue<SColor> outArray = new Queue<SColor>(m_scaleSizeX * m_scaleSizeY);
int idx =0;
for(int y = -m_scaleSizeY;y < (m_scaleSizeY +1);y++)
{
for(int x = -m_scaleSizeX;x < (m_scaleSizeX +1);x++)
{
int pX = (int)System.Math.Round( _x * m_scaleX + x);
int pY = (int)System.Math.Round( _y * m_scaleY + y);
//image bounds check
if(pX >= 0 && pY >= 0)
{
if(pX < m_width && pY < m_height)
{
idx = pX + pY * m_width;
outArray.Enqueue( m_originalColors[idx] );
}
}
}
}
return outArray.ToArray();
}
示例15: LoadContent
//.........这里部分代码省略.........
//shootbear 3 - 2d sea platform
bear2Box = new EnemyCompositeCharacter2(_world, new Vector2(7520f, 1580f), 93, 183, 0.15f, squareTex);
bearBox.forcePower = 100;
enemies2.Add(bear2Box);
//shootbear 3 - 3rd sea platform
bear2Box = new EnemyCompositeCharacter2(_world, new Vector2(8170f, 1880f), 93, 183, 0.15f, squareTex);
bearBox.forcePower = 100;
enemies2.Add(bear2Box);
//player ignore collisions with enemies
box.body.CollisionGroup = -1;
box.wheel.CollisionGroup = -1;
for (int i = 0; i < enemies.Count; i++)
{
enemies[i].body.CollisionGroup = -1;
enemies[i].wheel.CollisionGroup = -1;
}
for (int i = 0; i < enemies2.Count; i++)
{
enemies2[i].body.CollisionGroup = -1;
enemies2[i].wheel.CollisionGroup = -1;
}
//setup 3d sound
audioListener = new AudioListener();
//init bullet stuff
//bulletDirection = new Vector2(0, 0);
bulletQueue = new Queue<Bullet>();
tempBulletArray = bulletQueue.ToArray();
//setup deadzones
deadZones = new List<Rectangle>();
deadZones.Add(new Rectangle(2552, 1040, 402, 115)); //first pit
deadZones.Add(new Rectangle(6497, 1989, 402, 115)); //2nd
deadZones.Add(new Rectangle(7013, 1992, 502, 115)); //3rd pit
deadZones.Add(new Rectangle(7654, 2196, 702, 115)); //last pit
// Create the ground fixture
Body impassableEdge = BodyFactory.CreateEdge(_world, new Vector2(0f, 3f), new Vector2(0.25f, 3f));
impassableEdge.IsStatic = true;
impassableEdge.Restitution = 0.1f;
impassableEdge.Friction = 0.7f;
//From top of first cliff---------------------------------------------------------------------------------------
FixtureFactory.AttachEdge(new Vector2(-2.06f, 1.215f), new Vector2(-0.32f, 1.185f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(-0.32f, 1.185f), new Vector2(1.29f, 1.285f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(1.29f, 1.285f), new Vector2(2.37f, 1.315f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(2.37f, 1.315f), new Vector2(2.2f, 1.585f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(2.2f, 1.585f), new Vector2(2.08f, 1.645f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(2.08f, 1.645f), new Vector2(2.03f, 1.885f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(2.03f, 1.885f), new Vector2(1.69f, 2.005f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(1.69f, 2.005f), new Vector2(1.47f, 2.225f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(1.47f, 2.225f), new Vector2(1.44f, 2.425f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(1.44f, 2.425f), new Vector2(1.34f, 2.735f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(1.34f, 2.735f), new Vector2(1.41f, 2.965f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(1.41f, 2.965f), new Vector2(1.38f, 3.225f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(1.38f, 3.225f), new Vector2(1.35f, 3.585f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(1.35f, 3.585f), new Vector2(1.36f, 3.885f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(1.36f, 3.885f), new Vector2(1.42f, 4.155f), impassableEdge);
FixtureFactory.AttachEdge(new Vector2(1.42f, 4.155f), new Vector2(1.56f, 4.405f), impassableEdge);