Arrays

  • Thread starter Thread starter plork
  • Start date Start date
plork said:
I'm calling an external web service method and it retruns a complex
type which is an array

for (int i = 0; i < array.Length; i++)
{
ComplexType results = array ;


No, that's not a complex type which is an array - it's an array *of
ComplexType objects*.
each results looks like this when i look in visual studio
Array Result value
|-id "1000"
|-title "aaa"
|-description "some text"

all i want to do is loop through the 'array' retruned from the
webserivce call and group the 1000's together, 2000's together etc

i thought i could do this

for (int i = 0; i < array.Length; i++)
{
ComplexType results = array ;

if (results.id = "1000")
{
create another array
ComplexType 1000Array = new ComplexType ();
1000Array.add - but when i click CTRL+Space next to 1000Array i don't
get Add in the intellisense
}


Well, there are three reasons for this:

1) 1000Array isn't a valid identifier
2) ComplexType isn't an array
3) Array doesn't have an Add method anyway (leaving aside IList.Add)

Without wishing to be rude, I *strongly* suggest you learn some basic
C# before going into web services etc.
 
why not just use the ContainsKey method instead of TryGetValue?

Because I also wanted the value; TryGetValue does both at the same
time - otherwise I'd need to immediately follow it with a get on the
indexer.

Marc
 
Oboy. Does the WebService return WSDL? How are you accessing the webservice?
if your app is consuming the WSDL vai a webreference (e.g.
http://webservice/service1.asmx?WSDL ) then Visual Studio already generated a
proxy class that has a type that represents your results, and what you are
getting back is an array of that object.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com


plork said:
hi all i have a method that takes an array
e.g. public void Method (string [] array)
the contents of array are somthing like below, i don't know what the
length will be be until i do a array.Length

No they aren't, for the simple reason that each element of a string[] is a
single string, not a tuple (id, title, description). Perhaps you instead
want to pass an array of a user-defined type?




a snippet of results is
id title description
0] = "1000", "aaa", "some text"
[1] = "1000", "bbb", "some text"
[2] = "1000", "ccc", "some text"
[3] = "2000", "ddd", "some text"
[4] = "2000", "eee", "some text"
[5] = "3000", "fff", "some text"
[6] = "3000", "ggg", "some text"
[7] = "3000", "hhh", "some text"
[8] = "4000", "iii", "some text"
[9] = "5000", "jjj", "some text"
[10] = "6000", "kkk", "some text"
If i do this for (int i = 0; i < array.Length; i++)
i can see the length of the whole array
But is anyone able to show me how i get the length of id? e.g. I want
to see how many results have an id of e.g. 1000 or id of 2000
etc ....and then loop through those results- Hide quoted text -

- Show quoted text -

when i do an quick watch in vissual studio the vlaues are like below

Array Result value
|-id "1000"
|-title "aaa"
|-description "some text"
 

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

array of arrays 2
Compare cells in different worksheets 3
Group/Sort records in Excel 1
Excel Issue 1
EXCEL issue 3
Lookup with loop 3
How to Fill Empty Cells with Data from Previous Records 1
row comparison 5

Back
Top