[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

classes and structures

Posted on 2011-05-04
7
Medium Priority
?
264 Views
Last Modified: 2012-05-11
What is the difference between a structure and a class and when would you use on or the other.

An example of where you would use the structure rather then a class would be great
0
Comment
Question by:runnerjp2005
7 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35689316
A structure is usually used to hold Data where as a class can include the functionality.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35689321
A structure is usually used where multiple values need to be passed around, such as a return value of a function.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35689342
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:runnerjp2005
ID: 35689368
so is one a reference to data and the other is data itself.

I also though structures and classes can both hold vunctions.

ones by ref and other is by val ?
0
 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 35689373
Hi,
Th main points in class vs structure are:
Inheritence
Pass by Reference and Pass by Value

Please go throught the following links for more details:

http://dotnetguts.blogspot.com/2007/07/struct-vs-class-in-net.html
http://www.codeproject.com/KB/dotnet/Structures_VBNet.aspx
http://msdn.microsoft.com/en-us/library/aa289521(v=vs.71).aspx
Thanks
0
 
LVL 12

Accepted Solution

by:
Mohamed Abowarda earned 2000 total points
ID: 35690714
Structs differ from classes in several important ways:

- Structs are value types.
- All struct types implicitly inherit from the class System.ValueType.
- Assignment to a variable of a struct type creates a copy of the value being assigned.
- The default value of a struct is the value produced by setting all value type fields to their default value and all reference type fields to null.
- Boxing and unboxing operations are used to convert between a struct type and object.
- The meaning of this is different for structs.
- Instance field declarations for a struct are not permitted to include variable initializers.
- A struct is not permitted to declare a parameterless instance constructor.
- A struct is not permitted to declare a destructor.
0
 
LVL 12

Assisted Solution

by:Mohamed Abowarda
Mohamed Abowarda earned 2000 total points
ID: 35690803
Structures are always better to declare a group of related variable, for example:
    Public Structure Person
        Public FirstName As String
        Public LastName As String
        Public Occupation As String
    End Structure

Open in new window


While it's better to use classes when you have methods, events, properties, etc...
Example:
    Public Class ImageProcessor
        ' Variables
        Private image As Bitmap

        ' Events
        Public Event ProcessCompleted(ByVal e As EventArgs)
        Public Event ProcessError(ByVal e As EventArgs)

        ' Methods
        Public Sub ImageProcessor()

        End Sub

        Public Sub Start()

        End Sub
    End Class

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question