Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return tuple with two arrays

Tags:

c#

tuples

I am trying to call a function which returns a tuple with two arrays. The content of the arrays are based on checked items in a checkedListBox. I define the arrays and call the function "storeParametersInArrays" as shown below.

string[] allowedObjects = new string[checkedListObjects.CheckedItems.Count]; // All allowed objects
string[] notallowedObjects = new string[checkedListObjects.Items.Count - checkedListObjects.CheckedItems.Count]; // All not allowed objects

Tuple<string[], string[]> ObjParameters = storeParametersInArrays(notallowedObjects, allowedObjects, checkedListObjects);
allowedObjects = ObjParameters.Item1;
notallowedObjects = ObjParameters.Item2;

The function called is defined as:

private Tuple<string[], string[]> storeParametersInArrays(string[] notallowed, string[] allowed, CheckedListBox checkedListBox)
{
    int i = 0; // allowed objects
    int j = 0; // not allowed objects
    int k = 0; // item counter

    foreach (object item in checkedListBox.Items)
    {
        if (!checkedListBox.CheckedItems.Contains(item))
        {
            notallowed[j++] = checkedListBox.Items[k].ToString();
        }
        else
        {
            allowed[i++] = checkedListBox.Items[k].ToString();
        }
        k++;
    }
    return Tuple.Create<allowed, notallowed>;
}

I am unable to return the Tuple in the above code sample. I get the error "Cannot convert method group 'Create' to non-delegate type 'Tuple'".

It is my first time working with tuples, how can I return the two arrays without having to call the function twice?

I have looked at slightly similar problems, so if the question is already answered somewhere else, I will be glad to be pointed in the right direction.

like image 788
ChrisRun Avatar asked Jan 01 '23 03:01

ChrisRun


1 Answers

Just change

return Tuple.Create<allowed, notallowed>;

to

return Tuple.Create(allowed, notallowed);

The first syntax is for generics: <

The second for method calls: (

like image 161
Flat Eric Avatar answered Jan 16 '23 20:01

Flat Eric