How to iterate through a list using c#?

zenfreak

Client
Регистрация
21.08.2013
Сообщения
249
Благодарностей
12
Баллы
18
I want to iterate through a list using c# in zenno.

I have this code:

Код:
int count = project.Lists["myList"].Count;

for (int i = 0; i<count; i++){
var k = project.Lists["myList"].GetItem("i", false);
}
This throws an error: Invalid format of the collection numbers. ElementsInCollection: 94 Path i
or
Cannot convert from int to string if I only use i without quotes so It's obvious it expects a string and not an int

Replacing i with 0 works!
Код:
int count = project.Lists["myList"].Count;

for (int i = 0; i<count; i++){
var k = project.Lists["myList"].GetItem("0", false);
}
I can also just use 0 and remove the items from list like this:

Код:
int count = project.Lists["myList"].Count;

for (int i = 0; i<count; i++){
var k = project.Lists["myList"].GetItem("0", true);
}
But removing the items from the list is not what I need.
 

zenfreak

Client
Регистрация
21.08.2013
Сообщения
249
Благодарностей
12
Баллы
18
The weird thing is that GetItem expects a string value instead of an integer (as every programming language would expect for a list item index) so converting it to string solved the problem

Код:
i.ToString();
 
  • Спасибо
Реакции: Mikhail B.

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)