it looks like you are doing a lot with making all sorts of variables that are really confusing to look at, maybe I am simple minded and that is why I can't figure it all out.
not really sure what you are doing with the t but I changed it to i
XmlNodelist ClientNodes;
ClientNodes = Clientes[0].ChildNodes;
XmlNode ChildNode;
int i = 0;
foreach ChildNode in ClienteNodes
{
i++
XmlNodeList ClientChildNodes;
XmlNode ClientChildNodeChild; //don't keep my name scheme
foreach ClientChildNodeChild in ClientChildNodes
{
string clientZeroItemTchildIname;
clientZeroItemTchildIname = (ClientChildNodeChild.Item.Name).ToUpper();
if ( ClientZeroItemTchildIname.Contains("SERVICE"))
{
int a = 0;
int.TryParse(ClientZeroItemTchildIname.Replace("SERVICE",""),out a);
if (a.Equals(Type))
{
try
{
Queues[i].Send(QueueMessage)
}
catch (MessageQueueException mqe)
{
//log Error about mqe
}
}
}
}
}
not sure that I made it any faster, but this is way more readable.
there is one less Variable in my code than there is in your 'optimized' code.
I Do not know about the difference between foreach and for(int i = 0;i < x; i++) loops.
here is an answer to that question, where someone actually went through testing for loops against foreach loops. and it looks like the foreach is faster in some instances.
Answer to Performance difference for control structures 'for' and 'foreach' in C# (2009)
I also found a page where someone claims that a foreach loop takes longer and is generally good for collections, but then he recommends against it anyway.
Code Project Article "FOREACH Vs. FOR (C#)" (2004)
threw that one in there in case you thought that I was biased. I still think the foreach would be better for readability, but I don't know what your code is doing so I don't know what is going to be more efficient for you. Readable/maintainable vs. faster? maybe. not sure though.
Something else to think about
taking the Send out of the Loop.
keep track of which Queues that you want to send in a variable outside of the loop and then once you are finished looping then send them all at the same time, outside of the loop. not sure how you would accomplish this, it was an afterthought.