I often find myself doing the following index-counter messiness in a foreach loop to find out if I am on the first element or not. Is there a more elegant way to do this in C#, something along the lines of if(this.foreach.Pass == 1) etc.?
int index = 0;
foreach (var websitePage in websitePages)
{
if(index == 0)
classAttribut...
Hi All,
I'm running a RegEx to match all instances of the Twitter hashtag. It returns it just fine, but now I just want to loop through the first set and return my #hello, #world, #hello-world....not the second set. Any help will be quickly rewarded!
Array
(
[0] => Array
(
[0] => #hello
[1] => #wor...
I've got a map that stores a simple struct with a key. The struct has two member functions, one is const the other not. I've managed calling the const function using std::for_each without any problems, but I've got some problems calling the non-const function.
struct MyStruct {
void someConstFunction() const;
void someFunction();
};...
Hi, I'm a big fan of using the forEach method on nodeLists like this:
var nodes = document.querySelectorAll(".foo");
[].forEach.call(nodes, function (item) {
//do stuff with item
});
I was wondering though, does doing it that way take longer than the regular way?
e.g.
for(var i=0;i<nodes.length;i++){
//do stuff with nodes[i]...
Is there a reason why I can't do the following:
foreach (var Item in DataTable.Rows) {
rather than having to do
foreach (DataRow Item in DataTable.Rows) {
I would have thought this was possible, like it is on other datatypes. For example:
foreach (var Employee in Staff) { // string[] Staff etc...
When I try the first foreach loo...
I'm using a foreach currently, and need the index of the item.
foreach (DataRow m_row in base_rows)
{
Company nu = new Company(m_row, symb_rows[0]);
}
Here's the code.
I'm trying to get the index of m_row inside of base_rows and use that to pass symb_rows[index_of_m_row]. Is this possible or shoul...
I have an NAnt task "ship" to package my current .sql scripts into a build, then name the build with an incrementing int {######} and copy it to a build folder. I have another NAnt task which executes those build scripts. They must execute in order, but in my last attempt, they were not. Can I "force" NAnt to work alphabetically?
Tha...
I am relatively new to Perl and I do not want to use the List::Util max function to find the maximum value of a given array.
When I test the code below, it just returns the first value of the array, not the maximum.
sub max
{
my @array = shift;
my $cur = $array[0];
foreach $i (@array)
{
if($i > $cur)
{
...
I have seen a few examples of how to do this with winforms but have been unable to get it to work in wpf as a wpf TabItem does not have a definition for Controls. Here is the code that I'm using right now, which does not work.
TabItem ti = rep1Tab;
var controls = ti.Controls;
foreach (var control in con...
Basically I'm doing the following:
std::set<int> indices;
// ..fill indices
if (flag)
{
// we need to process in ascending order
BOOST_FOREACH (int i, indices)
{
process(i);
}
}
else
{
// we need to process in descending order
BOOST_REVERSE_FOREACH (int i, indices)
{
process(i);
}
}
I wonder if ...
I have a gridview and i am converting gridview rows to a datatable... But i cant able to get the value of a hiddenfield in cell[0] inside the gridview....
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("EmpId", typeof(Int64)));
dt.Columns.Add(new DataColumn("FromDate", typeof(DateTime)));
dt.Columns.Add(ne...
Hi I have the following JSON returned in a variable called data.
THIS IS THE JSON THAT GETS RETURNED...
[
{"Id": 10004, "PageName": "club"},
{"Id": 10040, "PageName": "qaz"},
{"Id": 10059, "PageName": "jjjjjjj"}
]
and I am trying to loop through the collection using $.each but I am running into problems where the alert is showing ...
Hi,
I'm wondering how to iterate over a List with mixed contents using foreach. See the example code below.
public class GenericsForeach {
class A {
void methodA() {
System.out.println(getClass().getSimpleName() + ": A");
}
}
class B extends A {
void methodB() {
System.out.p...
In Java, I want to go through a list of elements and insert a new one at the right place. I was thinking of doing it in this way:
for( Tab tab : tabList )
if( newTab.getPriority() < tab.getPriority() ) {
newTab.insertBefore(tab);
break;
}
if( tab == null )
newTab.insertBefore(endMarker);
Unfortunately, tab is not accessi...
I am new to Eclipse which I use primarily for Java. I have previously used IntelliJ Idea in which it is possible to select a variable which extends Iteratable (Collection, List etc) and have it produce a correct foreach loop.
I know Eclipse does something similar with the foreach template, where it guesses which variable to iterate over...
$mainMenu['Home'][1] = '/mult/index.php';
$mainMenu['Map'][1] = '/mult/kar.php';
$mainMenu['MapA'][2] = '/mult/kara.php';
$mainMenu['MapB'][2] = '/mult/karb.php';
$mainMenu['Contact'][1] = '/mult/sni.php';
$mainMenu['Bla'][1] = '/mult/vid.php';
This is a menu, 1 indicates the main part, 2 indicates the sub-menu. Like:
Home
Map
-MapA...
I have a list like this
Dim emailList as new List(Of String)
emailList.Add("[email protected]")
emailList.Add("[email protected]")
emaillist.Add("[email protected]")
How can I iterate the list with ForEach to get one string with the emails like this
[email protected];[email protected];[email protected]
...
Hello
While I was trying something special in for loop I recognized that Java doesn't seem to like putting an anonymous array right as the source for a for-each-loop:
for (String crt : {"a","b","c"} ) {
doSomething();
}
actually doesn't work while
String[] arr = {"a","b","c"};
for (String crt : arr ) {
doSomething();
}
doe...
I am wondering if there is any benefit to getting a reference to a vector prior to calling
BOOST_FOREACH or whether a method call which returns a reference will be automatically used? For example which of the two following loops will be equivalent to the third loop?
vector<float>& my_method();
void main()
{
// LOOP 1 -------------...
I store serialized data in the registry. I want to use a foreach loop to iterate through that data. On each iteration I would like to add that data to a dictionary. As follows:
// Create dictionary
myDictionary = new Dictionary();
// iterate through previously stored data and add it to Dictionary
foreach (object x in Application.User...