473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Returning an array of an object

Can someone tell me what I am doing wrong here? This will not compile
because of line 2, but if I replace with Service.ContactTO[] contacts = null;
it will through an exception on line 3.

Thanks

1Service.ContactTO cntTO = new Service.ContactTO();
2 Service.ContactTO[] contacts = new Service.ContactTO();
3 contacts[0] = createNewContact1();

4 private Service.ContactTO createNewContact1()
5 {

6 Service.ContactTO cnt = new Service.ContactTO();
7 cnt.firstName = "Neil";
8 cnt.lastName = "Armstrong";
9 cnt.prefix = "Mr.";
10 return cnt;
}

--
David R
Aug 8 '06 #1
2 991
You are creating a instance of ContactTo to an array of that type which is
invalid. Let the 2nd line be:

Service.ContactTO[] contacts = {createNewContact1()};

"David R" <Da****@discussions.microsoft.comwrote in message
news:8A**********************************@microsof t.com...
Can someone tell me what I am doing wrong here? This will not compile
because of line 2, but if I replace with Service.ContactTO[] contacts =
null;
it will through an exception on line 3.

Thanks

1Service.ContactTO cntTO = new Service.ContactTO();
2 Service.ContactTO[] contacts = new Service.ContactTO();
3 contacts[0] = createNewContact1();

4 private Service.ContactTO createNewContact1()
5 {

6 Service.ContactTO cnt = new Service.ContactTO();
7 cnt.firstName = "Neil";
8 cnt.lastName = "Armstrong";
9 cnt.prefix = "Mr.";
10 return cnt;
}

--
David R

Aug 8 '06 #2
That did the trick.

Thanks!

--
David R
"Siva M" wrote:
You are creating a instance of ContactTo to an array of that type which is
invalid. Let the 2nd line be:

Service.ContactTO[] contacts = {createNewContact1()};

"David R" <Da****@discussions.microsoft.comwrote in message
news:8A**********************************@microsof t.com...
Can someone tell me what I am doing wrong here? This will not compile
because of line 2, but if I replace with Service.ContactTO[] contacts =
null;
it will through an exception on line 3.

Thanks

1Service.ContactTO cntTO = new Service.ContactTO();
2 Service.ContactTO[] contacts = new Service.ContactTO();
3 contacts[0] = createNewContact1();

4 private Service.ContactTO createNewContact1()
5 {

6 Service.ContactTO cnt = new Service.ContactTO();
7 cnt.firstName = "Neil";
8 cnt.lastName = "Armstrong";
9 cnt.prefix = "Mr.";
10 return cnt;
}

--
David R

Aug 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Krackers | last post by:
How do you write a function which returns a reference to an array. I can only get a function to return a copy of the array itself. I've had a look at some other threads in this group an the return...
5
by: Gent | last post by:
I have two questions which are very similar: Is it possible to return an object in C++. Below is part of my code for reference however I am more concerned about the concept. It seems like the...
3
by: Faustino Dina | last post by:
Hi, The following code is from an article published in Informit.com at http://www.informit.com/guides/content.asp?g=dotnet&seqNum=142. The problem is the author says it is not a good idea to...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
5
by: shyam | last post by:
Hi All I have to write a function which basically takes in a string and returns an unknown number( at compile time) of strings i hav the following syntax in mind char *tokenize(char *) ...
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
0
by: anuptosh | last post by:
Hi, I have been trying to run the below example to get a Oracle Array as an output from a Java code. This is an example I have found on the web. But, the expected result is that the code should...
8
by: darren | last post by:
Hi everybody, have a quick look at this code: ===== ===== int main(void) { string msg; makeString(msg); cout << "back in main, result = " << msg << endl;
160
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
5
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.