A
A
Albert2015-03-07 12:12:48
Programming
Albert, 2015-03-07 12:12:48

C# Array get from function?

Good afternoon!
I almost never do programming, but for self-development I sometimes try all sorts of jokes, so please don’t throw stones.
The question is this:
There is a Form class in which the UserId() function is called by clicking on the button;

private void button1_Click(object sender, EventArgs e)
        {
            UserId();
        }

result = ServerApi.GetUserId();
The UserId function is located in the same class and sends a request to the server to receive an XML response that contains the information I am interested in, I am satisfied with the execution of this code, the result suits me: located in the ServerApiParsXml class to get the fields of interest to me and write the already prepared response to a variable:
string UserNotMemberGroup = ServerApiParsXml.UserNotMemberGroupp(result.SelectSingleNode("response")).ToString();

UserID function:
private void UserId() 
        {
            result = ServerApi.GetUserId();
            string[] UserNotMemberGroup = ServerApiParsXml.UserNotMemberGroupp(result.SelectSingleNode("response")).ToString();
        }

This is where the fun begins, at least for me the string UserNotMemberGroup variable is defined as because I thought to get the values ​​​​in string form, but then it became necessary to have an array, at least it will be easier for me to work with it in the future.
ServerApiParsXml class UserNotMemberGroupp() function;
public static string UserNotMemberGroupp(XmlNode n)
        {
// выставляю счетчики в 0
            int i = 0, b = 0, e = 0;
//считаю количество узлов mem в XML документе для задания размера массива 
            int d = n.SelectNodes("mem").Count;
//Определяю массив для хранения пользователей не входящих в группу
            string[] UserNotGroup = new string[d];
//Определяю массив для хранения пользователей входящих в группу
            string[] UserGroup = new string[d];
//Определяю два массива user и mem для хранения в последовательности 1 к 1
//Данных полученных с XML документа 
//До этого делал string[,] user = new string [d,3] 
//- третий параметр я пока убрал хотя тоже нужная весч 
            string[] user =new string [d];
            string[] mem = new string [d];
//foreach у меня занимается тупой фасовкой данных по мне это щас самый простой способ
//кто подскажет лучше буду благодарен
            foreach (XmlNode userMemGroupNode in n.ChildNodes)
            {
                if (userMemGroupNode.Name == "mem")
                {

                    member[i] = userMemGroupNode.InnerText;
                    i++;
                }
                else
                {

                    user[b] = userMemGroupNode.InnerText;
                    b++;
                }
            }
//иду по массиву mem и если получаю значение 0
// то беру из массива user под тем же индексом значение и ложу в переменную для 
//возврата в функцию UserId() и присвоения переменной string UserNotMemberGroup
for (int c = 0; c < mem.Length; c++)
            {
                if (mem[c] == "0")
                {
                    UserNotGroup[e] = user[c];
                    e++;
}
 return UserNotGroup[e];
        }

Attention to the question:
How can I pass the UserNotGroup[e] array from the ServerApiParsXml class to the Form class and assign the UserId() function to a variable
string[] UserNotMemberGroup = ServerApiParsXml.UserNotMemberGroupp(result.SelectSingleNode("response")).ToString();

as I understand this whole question is garbage to the right of the variable
ServerApiParsXml.UserNotMemberGroupp(result.SelectSingleNode("response")).ToString();

should do all its work and return the value
return UserNotGroup[e];
which in turn will be assigned to the variable
string[] UserNotMemberGroup
Help whoever can :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Puma Thailand, 2015-03-07
@6ETuK

Remove the ToString() conversion

var  UserNotMemberGroup=ServerApiParsXml.UserNotMemberGroupp(result.SelectSingleNode("response"));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question