Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
LINQ Reporting Engine provides special extension methods for iteration variables of any type. You can normally use these extension methods in template expressions. The following list describes the extension methods.
Returns the zero-based index of a sequence item that is represented by the corresponding iteration variable. You can use this extension method to distinguish sequence items with different indexes and then handle them in different ways. For example, given that items is an enumeration of the strings “item1”, “item2”, and “item3”, you can use the following template to enumerate them prefixing all of them but the first one with commas.
The items are: <<foreach [
item in items]>><<[item.indexOf() != 0
? ", "
: ""]>><<[item]>><</foreach>>.
In this case, the engine produces a report as follows.
The items are: item1, item2, item3.
Returns the one-based index of a sequence item that is represented by the corresponding iteration variable. You can use this extension method to number sequence items without involving Microsoft Word® lists. For example, given the previous declaration of items, you can enumerate and number them in a document table using the following template.
| No. | Item |
|---|---|
|
|
In this case, the engine produces a report as follows.
| No. | Item |
|---|---|
| 1 | item1 |
| 2 | item2 |
| 3 | item3 |
Q: How can I obtain the zero‑based position of the current item inside a foreach loop?
A: Use the indexOf() extension method on the iteration variable, e.g., <<[item.indexOf()]>>. It returns 0 for the first element, 1 for the second, and so on.
Q: What method should I use to get a one‑based (human‑friendly) index for numbering items?
A: Call numberOf() on the iteration variable, e.g., <<[item.numberOf()]>>. This returns 1 for the first element, 2 for the second, etc., which is useful for creating numbered lists without Word list formatting.
Q: Can I use these extension methods inside conditional expressions to treat the first or last element differently?
A: Yes. For example, <<[item.indexOf() == 0 ? "First:" : ""]>> adds a prefix only to the first item, and <<[item.numberOf() == items.Count ? " (last)" : ""]>> can identify the last element.
Q: How do I add a separator (such as a comma) before every item except the first one?
A: Combine indexOf() with a conditional expression: <<[item.indexOf() != 0 ? ", " : ""]>>. This inserts the separator only when the current index is not zero.
Q: Are indexOf() and numberOf() limited to string collections, or can they be used with any enumerable type?
A: They work with iteration variables of any type—lists of objects, custom classes, or primitive types—because the methods operate on the position of the item in the sequence, not on the item’s value.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.