Howdy,
I need to set the height of every textbox on my form, some of which are nested within other controls. I thought I could do something like this:
private static IEnumerator<TextBox> FindTextBoxes(Control rootControl){ foreach (Control control in rootControl.Controls) { if (control.Controls.Count > 0) { ...
I have the following code snippet.
$items['A'] = "Test";
$items['B'] = "Test";
$items['C'] = "Test";
$items['D'] = "Test";
$index = 0;
foreach($items as $key => $value)
{
echo "$index is a $key containing $value\n";
$index++;
}
Expected output:
0 is a A containing Test
1 is a B containing Test
2 is a C containing Test
3 is a...
There doesn't seem to be a dictionary.AddRange() method. Does anyone know a better way to copy the items to another dictionary without using a foreach loop.
I'm using the System.Collections.Generic.Dictionary. This is for .NET 2.0.
...
Something like:
//Get all search data
$search = new search('C:\', '*.exe');
while($item = $search->next())
{
$details = $item->getDetails();
append_details('C:\files.txt', implode_details($details));
}
But in NSIS (http://nsis.sourceforge.net/)
...
This is in C#, I have a class that I am using from some else's DLL. It does not implement IEnumerable but has 2 methods that pass back a IEnumerator. Is there a way I can use a foreach loop on these. The class I am using is sealed.
...
Hi all,
Is it possible to find the foreach index?
in a "for" loop as follows:
for($i = 0; $i < 10; ++$i){
echo $i.' ';
}
$i will give you the index.
Do I have to use the for loop or is there some way to get the index in the foreach loop?
...
Is it safe to assume that two itterations over the same collection will return the objects in the same order? Obviously, it is assumed that the collection has not otherwise been changed.
...
I only just recently discovered that Visual C++ 2008 (and perhaps earlier versions as well?) supports for each syntax on stl lists et al to facilitate iteration.
For example:
list<Object> myList;
for each (Object o in myList)
{
o.foo();
}
I was very happy to discover it, but I'm concerned about portability for the dreaded day when ...
I'd like to do the equivalent of the following in LINQ, but I can't figure out how:
IEnumerable<Item> items = GetItems();
items.ForEach(i => i.DoStuff());
What is the real syntax?
...
I tried the following code in LINQPad and got the results given below:
List<string> listFromSplit = new List<string>("a, b".Split(",".ToCharArray())).Dump();
listFromSplit.ForEach(delegate(string s)
{
s.Trim();
});
listFromSplit.Dump();
"a" and " b"
so the letter b didn't get the white-space removed as I was expecting...?
A...
I'm wondering if PHP has this optimization built in. Normally when you call foreach without using a reference it copies the passed array and operates on it. What happens if the reference count to that array is only 1?
Say for example if getData returns some array of data.
foreach(getData() as $data)
echo $data;
Since the array ...
Hi all,
I saw a code snippet yesterday in one of the responses here on StackOverflow that intrigued me. It was something like this:
List<string> myList = new List<string> {"aBc", "HELLO", "GoodBye"};
myList.ForEach(d=>d.ToLower());
I was hoping I could use it to convert all items in myList to lowercase. However, it doesn't happen...
Is there a way to use a foreach loop to iterate through a collection backwards or in a completely random order?
...
Let's start with the following snippet:
Foreach(Record item in RecordList){
..
item = UpdateRecord(item, 5);
..
}
The UpdateRecode function changes some field of item and returns the altered object. In this case the compiler throws an exception saying that the item can not be updated in a foreach iteration.
Now the UpdateRecor...
public Int64 ReturnDifferenceA()
{
User[] arrayList;
Int64 firstTicks;
IList<User> userList;
Int64 secondTicks;
System.Diagnostics.Stopwatch watch;
userList = Enumerable
.Range(0, 1000)
.Select(currentItem => new User()).ToList();
arrayList = userList.ToArray();
watch = new Stopwatch();
wa...
I've found what seems to be the C# equivalent of a FOR-CASE structure in a proyect I'm working on:
foreach (string param in params.Split(';'))
{
string[] parts = param.Split('=');
string key = parts[0].Trim().ToLower();
string value = parts[1].Trim();
switch (key)
{
case "param1": this.param1 = value; break;
...
Can someone share a simple example of using the foreach keyword with custom objects?
...
How can I determine if I'm in the final loop of a For Each statement in VB.NET?
...
Many people ask me why, and I don`t have a good answer for them.
Obviously there is a good reason. Does anyone know it?
I searched here and found this question. It explains how it works, but not why.
...
I don't understand which types of classes can use foreach loops. Please help!
...