how to deal with a method that returns object array?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi there,
i have a following method which returns array of object.

public myresult[] getSearch(string searchterm)
{
object[] res = ....some external method call
return ((myresult[]) (res[0]));
}

so my question is... how do i consume the above method? can i do the
following?
myresult[] res = getSearch("hello");

thanks...a
 
Ace said:
hi there,
i have a following method which returns array of object.

public myresult[] getSearch(string searchterm)
{
object[] res = ....some external method call
return ((myresult[]) (res[0]));
}

so my question is... how do i consume the above method? can i do the
following?
myresult[] res = getSearch("hello");

Yes. Did you try it before posting? What went wrong?
 
thanks bunch.
in fact, i tried it and it compiled and ran fine. however, the problem is
that res is null after making a call to getSearch() (which is a web service)
and i was not sure if i was doing it wrong or it is just supposed to be null.

btw, if i were to loop through this array, is it the correct syntax?

foreach (myresult x in res)
{
}

-a
Jon Skeet said:
Ace said:
hi there,
i have a following method which returns array of object.

public myresult[] getSearch(string searchterm)
{
object[] res = ....some external method call
return ((myresult[]) (res[0]));
}

so my question is... how do i consume the above method? can i do the
following?
myresult[] res = getSearch("hello");

Yes. Did you try it before posting? What went wrong?
 
oh... all looks good now. it was just because the web service really did not
return any matches.
thanks all...a

Ace said:
thanks bunch.
in fact, i tried it and it compiled and ran fine. however, the problem is
that res is null after making a call to getSearch() (which is a web service)
and i was not sure if i was doing it wrong or it is just supposed to be null.

btw, if i were to loop through this array, is it the correct syntax?

foreach (myresult x in res)
{
}

-a
Jon Skeet said:
Ace said:
hi there,
i have a following method which returns array of object.

public myresult[] getSearch(string searchterm)
{
object[] res = ....some external method call
return ((myresult[]) (res[0]));
}

so my question is... how do i consume the above method? can i do the
following?
myresult[] res = getSearch("hello");

Yes. Did you try it before posting? What went wrong?
 
Ace said:
thanks bunch.
in fact, i tried it and it compiled and ran fine. however, the problem is
that res is null after making a call to getSearch() (which is a web service)
and i was not sure if i was doing it wrong or it is just supposed to be null.

Well, to check whether that kind of thing is valid or not, I'd suggest
trying it in a simpler environment first.
btw, if i were to loop through this array, is it the correct syntax?

foreach (myresult x in res)
{
}

Yes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top