adspace


When do you generally use a class over a struct?

Answer Posted / Ankit Srivastava

Use a class when:
1. You need to create an object with state that can change during the lifetime of the object.
2. The object needs to be subclassed or inherit from other classes.
3. The object requires methods in addition to properties.nUse a struct when:
1. The value is small and frequently used as a parameter for methods without needing to change its state.
2. It's more efficient memory-wise than using a class (due to stack allocation instead of heap allocation).

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you inherit a class into other class in c#?

1001


What is an abstract class c#?

978


Why can't we use a static class instead of singleton?

963


Which namespaces are necessary to create a localized application?

1151


How to assign Null value to Var?

1073


What is expression tree in c#?

1007