structures vs classes

G

Gian U. Uy

Hi!

I'd like to know is what are the prons and cons of using structures (data
types declared as struct [in c#] or structure [in vb.net]) as against
classes when passing data from and to a web service?
 
S

Scott M.

In general, structures should be used for managing the state (property
values - data) of something and classes should be used to manage state and
behavior (methods) of something.

Because structures are value types, they are managed on the stack as opposed
to classes, which are reference types and therefore managed on the heap.
Since the stack is a more limited storage area than the heap, thinner
objects are generally placed there and more complex objects (classes) go on
the heap, which is a bigger storage area.

Also, with value types (structures), you can easily pass them ByVal whereas
with a reference type (classes), you pass ByRef.
 
S

Saurabh Nandu

Hi,

There is no such difference from a Web Service point of view, since the data
sent over the web service is in XML format which is independent of being
generated from a class or struct.'


Regards,
Akila
[MVP]
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top