adspace


What is the difference between struct and class c#?

Answer Posted / Avneesh Sharma

In C#, both Struct (struct) and Class are user-defined data types. However, there are some differences:
1. By default, classes are reference types, while structs are value types.
2. Classes support inheritance with ':' operator, but structs do not. The ':' operator in structs is used for indexer declarations.
3. Classes can have a constructor, whereas structs are instantiated using the default constructor unless explicitly defined.
4. Struct fields are public by default and cannot be private or protected, while class fields can be any access modifier (public, private, protected).

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

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

954


What is expression tree in c#?

998


What is an abstract class c#?

969


Which namespaces are necessary to create a localized application?

1142


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

993


How to assign Null value to Var?

1063