Check if already exists in list/table

awzse00

Client
Регистрация
16.03.2013
Сообщения
231
Благодарностей
36
Баллы
28
Hi guys i'm trying to figure out how this snippet works, is it still up to date? Because i'm trying for the last 2 hours to get it running.
Basically i need to check if a Dealer is in my list already or not. If it's there, stop the action ,if it isn't continue with the template.

Код:
// take search text from variable
var textContains = project.Variables["DealerName"].Value;
// get a list or search
var sourceList = project.Lists["Dealeri"];
// search in each line of list
lock(SyncObjects.ListSyncer)
{
    for(int i=0; i < sourceList.Count; i++)
    {
        // get line from list
        var str = sourceList[i];
        // check if line contains text, if there are matches return "yes"
        if (str.Contains(textContains))
            return "yes";
    }
}
// ifnothing found return "no"
return "no";
 

Alexandre

Новичок
Регистрация
30.09.2016
Сообщения
26
Благодарностей
3
Баллы
3
It can be obvious, but did you uncheck do not return a value option on C# module window?
 

amyboose

Client
Регистрация
21.04.2016
Сообщения
2 312
Благодарностей
1 191
Баллы
113
Код:
project.Variables["isContain"].Value = project.Lists["Dealeri"].Any(x => x.IndexOf(project.Variables["DealerName"].Value) != -1).ToString();
or
Код:
if (project.Lists["Dealeri"].Any(x => x.IndexOf(project.Variables["DealerName"].Value) != -1))
    throw new Exception();
 
Последнее редактирование:

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