What is the difference between a Struct and a Class



What is the difference between a Struct and a Class..

Answer / kirti

The struct type is suitable for representing lightweight objects such as Point, Rectangle, and Color. Although it is possible to represent a point as a class, a struct is more efficient in some scenarios. For example, if you declare an array of 1000 Point objects,

you will allocate additional memory for referencing each object. In this case, the struct is less expensive.

When you create a struct object using the new operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the new operator. If you do not use new, the fields will remain unassigned and the object cannot be used until all of the fields are initialized. It is an error to declare a default (parameterless) constructor for a struct. A default constructor is always provided to initialize the struct members to their default values.

It is an error to initialize an instance field in a struct.

There is no inheritance for structs as there is for classes. A struct cannot inherit from another struct or class, and it cannot be the base of a class. Structs, however, inherit from the base class Object. A struct can implement interfaces, and it does that exactly as classes do.

A struct is a value type, while a class is a reference type.

How big is the datatype int in .NET ?

32 bits.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Dot Net Framework Interview Questions

How to bind table coloum with gridview column

3 Answers   Sypher Technologies,


What is the difference between windows vista and .net framework 3.0 ?

0 Answers  


What is basic authentication in web api?

0 Answers  


If we write any code for DataGrid methods, what is the access specifier used for that methods in the code behind file and why?

0 Answers   Cap Gemini,


js fn to go to the particular page when enter is clicked

1 Answers  






Is any files are generated,when we are adding the web reference to the web service?

2 Answers  


Describe the advantages of writing a managed code application instead of unmanaged one. What's involved in certain piece of code being managed ?

1 Answers  


Is .net framework 4.8 the last version?

0 Answers  


Is it possible to create a custom filter?

0 Answers  


What are the Core features of ASP.NET MVC?

0 Answers  


Explain linq to entities? : Entity framework

0 Answers  


Explain the difference between viewbag and viewdata in mvc?

0 Answers  


Categories