|
-
Feb 22nd, 2007, 04:37 AM
#1
Thread Starter
Addicted Member
help with returning an array...
Ok, i have the following code, but im having trouble returning the array of BlogEntry objects....
Code:
BlogEntry[] _blogEntries = new BlogEntry[_totalEntries];
for (int i = 0; i <= _totalEntries; i++) {
BlogEntry _entry = new BlogEntry();
_entry.Id = (int)dsBlogPosts.Tables[0].Rows[i]["entry_id"];
_entry.Title = (string)dsBlogPosts.Tables[0].Rows[i]["entry_title"];
_entry.Post = (string)dsBlogPosts.Tables[0].Rows[i]["entry_post"];
_entry.PostDescription = (string)dsBlogPosts.Tables[0].Rows[i]["entry_post_desc"];
_entry.PostDate = (DateTime)dsBlogPosts.Tables[0].Rows[i]["entry_post_date"];
_entry.Ip = (string)dsBlogPosts.Tables[0].Rows[i]["entry_ip"];
_entry.CategoryName = (string)dsBlogPosts.Tables[0].Rows[i]["category_name"];
_entry.Author = (string)dsBlogPosts.Tables[0].Rows[i]["author_name"];
_entry.AuthorEmail = (string)dsBlogPosts.Tables[0].Rows[i]["author_email"];
_blogEntries[i] = _entry;
}
return _blogEntries;
i get an error on the 'return _blogEntries;' line. cannot convert type BlogEntry[] to BlogEntry is the error message...
if i do a 'return _blogEntries[];' i get a Expecting value...but a 'return _blogEntries[0];' works fine...will this return the first dimension of the array...or the first key...
whats the correct return syntax??
Thanks, Justin
-
Feb 22nd, 2007, 06:49 AM
#2
Re: help with returning an array...
You've declared your method as returning a BlogEntry rather than a BlogEntry[], i.e. an array of BlogEntry objects. That's what the error message is telling you. The method returns a BlogEntry and you're specifying a BlogEntry[] in the return statement. It cannot convert one to the other so it falls over.
-
Feb 22nd, 2007, 04:39 PM
#3
Thread Starter
Addicted Member
Re: help with returning an array...
 Originally Posted by jmcilhinney
You've declared your method as returning a BlogEntry rather than a BlogEntry[], i.e. an array of BlogEntry objects. That's what the error message is telling you. The method returns a BlogEntry and you're specifying a BlogEntry[] in the return statement. It cannot convert one to the other so it falls over.
ahh, see now that makes sense. how ever i didnt realise an object, and an array of that object were different objects.
Thanks for the reply...i love these forums, ya learn something new everyday
Justin
Last edited by effekt26; Feb 22nd, 2007 at 05:00 PM.
-
Feb 22nd, 2007, 06:30 PM
#4
Re: help with returning an array...
OOP mimics the real world. Are an egg and an egg carton different things? Yes they are: one is a container that can hold multiple instances of the other. So are a BlogEntry and a BlogEntry[].
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|