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 |
What is multithreading? What are the problems that comes with multithreading and how to manage them?
what is generics? can u explain 5 to 6 examples on generics that covers class,method,structure,list,delegates?
How do you comment out code in c#?
How do I create a delegate/multicastdelegate?
I have a class declared as below public class a { public void add() {} } What is the diference between a a1 =new a; and simply a a1;
In .NET which is the smallest unit of execution?
How to do and Apply Themes to Datagrid,Lable,Textbox,etc., in C#.NET 2005 Windows Application? (like who we will do themes in ASP.NET using .CSS and .SKIN files). Urgent!!
Can I fly with a loop recorder?
What debugging tools come with the .NET ssSDK?
Write a program to create a user control with name and surname as data members and login as method and also the code to call it. (Hint use event delegates) Practical Example of Passing an Events to delegates
If a.equals(b) is true then a.gethashcode & b.gethashcode must always return same hash code.
What is the difference between Java and .NET garbage collectors?
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)