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 |
Did a generic class can be inherited by a normal class?
What is response redirect in c#?
What is the main method?
Overloaded constructor will call default constructor internally?
Is clr a compiler?
What is web forms in c#?
write a program to find the biggest palindrome in the given string
code for arranging given number in possible permutation ways ex:123,321,312,132,231,213.
Does c# provide copy constructor?
Why reflection is used in c#?
What are actions in c#?
What is local function?