public string[] LandsKodComboBox(string[] dendei1, string[] dendei2)
        {
            string[] dendei1 = new string[5];
            string[] dendei2 = new string[7];
            //assign the array
            dendei1[2]="hello";
            //etc etc....

            return dendei1, dendei2;
        }

why cant i return both of them? or how do you write?
thank you
Dendei.

You can only return one item from a method, so if you have multiple items to return, you'll need to combine them in a struct or class.

I'm not sure what you think you are passing into this method.

Maybe it would be better for you to tell us what you are trying to acomplish, rather than how you want to do it :)

Create a struct with all the vars in it you want to return. Then return the struct.

@Mom erath im trying to get this method to fill two arrays with database info and then send them to my php code via wcf service

@ddanbe where do i create the struct? inside the method?

You normaly create a separate file for it. If you are using Visual Studio this should be easy. It can also be a class as Momerath pointed out.

Im amazed nobody has suggested using an out parameter here.

public string[] LandsKodComboBox(string[] dendei1, string[] dendei2, out string[] returnDendei)
        {
            string[] dendei1 = new string[5];
            string[] dendei2 = new string[7];
            //assign the array
            dendei1[2]="hello";
            //etc etc....
            returnDendei = dendei2;
            return dendei1;
        }

but how do i write the method then? then input and output is a object?

[OperationContract]
object LandsKodComboBox(Variables.Kunder Kund);

*
*

public object LandsKodComboBox(Variables.Kunder Kund)
{
    return kund;
}

something like this?

Method example:

public int MyMethod(int NumberToAddTo, out bool Success)
{
    NumberToAddTo++;
    Success = true;
    return NumberToAddTo;
}

Call Example:

public void FormMethod()
{
    bool MethodSuccessful;
    int Number = 10;

    Number = MyMethod(Number, out MethodSuccessful);
}

@MikeyIsMe

        public string[] LandsKodComboBox(string[] dendei1, string[] dendei2, 
        out string[] returnDendei)
        {
            string[] dendei1 = new string[5];
            string[] dendei2 = new string[7];
            //assign the array
            dendei1[2]="hello";
            //etc etc....
            returnDendei = dendei2;
            return dendei1;
        }

how does it work? i return dendei1 but now returnDendei? or does it return auto because its "out"?

cant you assign the returnDendei directly? :)

The out keyword is most often used if you want your method, to return something extra instead of returning a whole new object. The int.TryParse method is a good example of this. If you want to return more use class or struct.

but yes i think class or struct is better in this case but how do i write the method ddanbe?
how do you declare the return type class?

Cheers for the advice Dan

correct me if im wrong but this is how you create a method that takes a class as input and returns a string

//method
string LandsKodComboBox(Myclass class)
{
    return string;
}

//call
string LandsKodComboBox(myclass class);

But how do i declare that i will have a class as return aswell?
cant do

//method
    class LandsKodComboBox(Myclass theclass)
    {
        return theclass;
    }

    //call
    class LandsKodComboBox(myclass theclass);


    //or 


    //method
    object LandsKodComboBox(Myclass class)
    {
        return object;
    }

    //call
    object LandsKodComboBox(myclass class);

how do you tell the program that i will return a class??
^^

Im amazed nobody has suggested using an out parameter here.

I don't like using out paramters as they can cause side effects in your methods.

how do you tell the program that i will return a class??

class MyClassToReturn {
    // variables to hold data here, use your imagination
}

class MyOtherClassWithMethods {
    public MyClassToReturn MyMethodImCalling() {
        MyClassToReturn result = new MyClassToReturn();
        // set variables to the data you want here
        return result;
    }
}

A method has 4 parts:

  1. Access specifiers (public, private, static, etc.)
  2. Return type (void, int, Boolean, MyClassToReturn, etc.)
  3. Name (in the example above, MyMethodImCalling)
  4. Parameters (in the example, there are none)

thank you Momerath works like a charm :) just what i needed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.