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

What is MSIL, IL, CTS?

13 Answers  


How to set background for total website, on that another another layer, in that we keep website data,,for example see www.msn.com. On one faded background we ll have layer like other background..Do explain how its possible

2 Answers  


What is orm entity framework?

0 Answers  


Can we look at the IL for an assembly?

2 Answers  


About .NET Framework ?

5 Answers   MMTS,






Where is tempdata stored?

0 Answers  


What are the types of authentication in .net

1 Answers  


Explain the advantages and disadvantages of ASP.Net MVC over ASP.NET?

0 Answers  


How do you initiate a string without escaping each backslash ?

1 Answers  


Where The Inheritence is useful?How we decide the situation of inheritence

2 Answers  


How can we determine action invoked from HTTP GET or HTTP POST?

0 Answers  


Which is the best institute in hyderabad to learn DotNet?

152 Answers   Cygnet Infotech, Infosys, Student, SVIT, TCS,


Categories