Press "Enter" to skip to content

Tell me about the difference between classes and structures in .NET?

A: Structures and classes have a general grammar, but structures are subject to more restrictions than classes. The structure cannot declare that there is a default constructor, and the copy of the structure is created by the compiler.

And destroyed, so no default constructors and destructors are needed. Structures are value types, so changes made to structure variables do not affect their original values, and classes are application types.

Changing the value of its variable changes its original value. The declaration structure uses the Struck keyword to declare that the class uses the class keyword. When the structure is passed to the method, it is passed by value, not by reference. Unlike classes, instantiation of structures can be done without the New keyword. Classes can implement interfaces.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *