Changing objects value in foreach loop?

You cannot change the iteration variable of a foreach-loop, but you can change members of the iteration variable. Therefore change the ChangeName method to private void ChangeName(StudentDTO studentDTO) { studentDTO.name = SomeName; } Note that studentDTO is a reference type. Therefore there is no need to return the changed student. What the ChangeName method gets, … Read more

Looping over a string list

The source of your confusion is probably CMake’s peculiar interpretation of quoted strings. For example, the following all iterate over the list of strings correctly: (1) foreach(LETTER a b c) […] (2) foreach(LETTER a;b;c) […] (3) set(MYLIST “a;b;c”) foreach(LETTER ${MYLIST}) […] The only case where this does not work is (4) foreach(LETTER “a;b;c”) […] The … Read more

The invocation context (this) of the forEach function call

MDN states: array.forEach(callback[, thisArg]) If a thisArg parameter is provided to forEach, it will be used as the this value for each callback invocation as if callback.call(thisArg, element, index, array) was called. If thisArg is undefined or null, the this value within the function depends on whether the function is in strict mode or not … Read more

what’s the point of having both Iterator.forEachRemaining() and Iterable.forEach()?

To understand why the two methods both exist, you need to first understand what are Iterator and Iterable. An Iterator basically is something that has a “next element” and usually, an end. An Iterable is something that contains elements in a finite or infinite sequence and hence, can be iterated over by keep getting the … Read more

foreach day in month [duplicate]

You can write a helper method pretty easily: public static IEnumerable<DateTime> AllDatesInMonth(int year, int month) { int days = DateTime.DaysInMonth(year, month); for (int day = 1; day <= days; day++) { yield return new DateTime(year, month, day); } } Then call it with: foreach (DateTime date in AllDatesInMonth(2012, 1)) This is probably overkill for something … Read more

use xsl to output plain text

You can define a template to match on script/command and eliminate the xsl:for-each concat() can be used to shorten the expression and save you from explicitly inserting so many <xsl:text> and <xsl:value-of> elements. The use of an entity reference &#xA; for the carriage return, rather than relying on preserving the line-break between your <xsl:text> element … Read more

MySQL foreach alternative for procedure

Here’s the mysql reference for cursors. So I’m guessing it’s something like this: DECLARE done INT DEFAULT 0; DECLARE products_id INT; DECLARE result varchar(4000); DECLARE cur1 CURSOR FOR SELECT products_id FROM sets_products WHERE set_id = 1; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; OPEN cur1; REPEAT FETCH cur1 INTO products_id; IF NOT … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)