Object and field Returning

Hi,

I have a question that I need some assistance on. So, any feedback would be greatly appreciated and examples would be great as well.

If I have an object in a list, for instance, List<Cars>. If I want to return that with an addition row that indicates how many cars I have in that List. (i.e. Cars.Count) - how would I do that.

For instance, the cars contain:

Lexus, 2013, 4 door
Mercedes, 2012, 2 door
Jetta, 2008, 4 door
Explorer, 2010, 4 door
Jaquar, 2013, 4 door
Focus, 2007, 2 door
6

The cars are in the list of the Cars object and the 6 is the list count but I need them it to show like that on a return of a function.

How would/can I do that?

Any assistance would be greatly appreciated.

Thanks.
LVL 1
davismAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
You wouldn't.

Cars is a class which holds information about a car.

a car has no knowledge of other cars, or how many were returned in this thing called a query from the database.

You could, of course, just access the property of the list itself:

List<Cars> cars = new List<Cars>();
TheCount.Text = cars.Count;  //TheCount being a textbox or a label.
0
p_davisCommented:
you could make it a list of objects and then cast back....
or return a Tuple.
0
davismAuthor Commented:
Do you happen to have a sample of that? I'm not entirely sure I understand what you are getting at.

Thanks
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

p_davisCommented:
you would have your method return a tuple and then build and return it at the end.

Tuple<List<Cars>, Int32> retVal = new Tuple<List<Cars>, Int32>(yourListOfCars, yourListOfCars.Count);

and you would access the values with retVal.Item1 (your list) reVal.Item2 (the count)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
p_davisCommented:
there are a lot of tutorials out there using them... they don't want us to post links anymore.
0
p_davisCommented:
as far as the objects list:

            List<Object> objs = new List<object>();
            objs.Add(yourCarList);
            objs.Add(yourCarList.Count);
0
davismAuthor Commented:
p_davis,

I will take a look at the other tutorials.

With respect to objects list...yep, already tried something list that but didn't work out as expected.

I will take a look at that again.

I'll get back to you on info.

Thanks!
0
p_davisCommented:
Might be able to help further if you could tell us what you are going to need this setup for....
are you trying to bind something? are you trying to do something dynamically?
0
davismAuthor Commented:
It's basically like creating a file used for exchanging data that includes a header, body (content), and footer.

The typically, I have seen something and have something like this in a file context using like Perl, but this is coming from a web service response which will turn out to be a serialized xml and done in c#.
0
davismAuthor Commented:
Excellent p_davis! Worked like a charm through the web service. The soap nodes weren't all clear cut and the wsdl showed some strangeness when a tuple was used but it worked none-the-less.

Thanks!
0
p_davisCommented:
awesome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.