what are the differences b/w structure and class?
Answers were Sorted based on User's Feedback
Answer / purushotham .tella
Structures are Value-Types. This means, the data that they
contain is stored as a stack on the memory. Classes are
Reference-Types, means they are stored as a heap on the memory.
Structures are implicitly derived from a class called
System.ValueType.
| Is This Answer Correct ? | 14 Yes | 0 No |
Following are the key differences between them :-
1. Structure are value types and classes are reference
types.So structures use
stack and classes use heap.
2. Structures members can not be declared as protected ,
but class members can
be.You can not do inheritance in structures.
3. Structures do not require constructors while classes
require.
4. Objects created from classes are terminated using
Garbage collector.Structures are not destroyed using GC.
| Is This Answer Correct ? | 14 Yes | 0 No |
Answer / dhinakaran
Class is a reference Type.
structure is a value Type.
| Is This Answer Correct ? | 4 Yes | 0 No |
Answer / jones
***class can have constructor, but structure cant have
constructor.***
***class can have garbage collector, but structure cant
have garbage collector***
| Is This Answer Correct ? | 5 Yes | 2 No |
Answer / sai laxman
class ex:-
class classname
{
int a;
float b;
}
struct {
int a;
int b;
}struct name;
In the struct all members are by default public,
in the class we can deference it private,public,protected.
While Inheriting from the structure all the members are
public by default but in class it depends upon the data
access modifiers.
| Is This Answer Correct ? | 7 Yes | 6 No |
Answer / abhay k pandey
Structs many have constructors but they should not be
parameterless. Structs performs alomost all the tasks of a
class but differs at some points - structs don't support
inheritance hence there is no protected keyword with
structs. Note : still struct inherit from System.Object
| Is This Answer Correct ? | 1 Yes | 0 No |
Struct:-
-------
1) by default, Public
2) doesn't support OOP's Concepts.
3) doesn't support Constructor and Destructor member functions.
4) No Security for data.
Class:-
-------
1) by default ,Private
2) its support OOP's Concepts.
3) supports Constructor and Destructor .
4) provides highly security for user's data.
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / sagu
In classes we can code functions which is not possible in
structures. In structures the number of members is
restricted to ten.whereas in c language we can use as many
members we required.
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / srikanth chodavarapu
Following are the key differences between them :-
1. Structure are value types and classes are reference
types.So structures use
stack and classes use heap.
2. class can have constructor, but structure cant have
constructor.
3. class can have garbage collector, but structure cant
have garbage collector.
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / rajesh
the only main difference b/w structure and class is by
default all members of structure are "public" where as for
the class they are "private",other wise structure is same
as class.All these answers have no sense
| Is This Answer Correct ? | 3 Yes | 8 No |
how to implement singelton in C# & its uses?
Why do we use yield in c#?
how to calculate multiple pdf files page count?
Explain About Virtual functions and their use.
What are the 3 logical operators?
What does using do in c#?
What is the difference between ienumerable and enumerator?
What is orm in c#?
What?s the difference between the Debug class and Trace class?
What is expression tree in c#?
What is the use of return in c#?
What are the Types of assemblies that can be created in dotnet
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)