What is CrazyEngico.com (CE)?

CrazyEngico (CE) is a one-stop solution for interview questions and answers, domain knowledge, e-learning, tutorials, articles and many more learning material.
e-learning - Intelligent e-learning tutorials and articles
Domain Knowledge Learn about various business domains/verticals such as Banking, Financial, Insurance, Healthcare and many more...
Interview Questions and Answers - Post your questions and answers. 1000+ database of ready questions and answers available to prepare for an interview.
Tutorials - 300+ video tutorials from beginner to expert level.
Articles - 300+ technical articles to understand concepts.
Forum - A technical forum to post your queries/responses.

Search Questions

Interview Questions/Answers

Ads
Question
Interview Q & A >> C# >> Difference between a Struct and a Class

<< Previous Question Navigator Next >>

0        0
Difference between a Struct and a Class (Views: 2063)


Answers

1        0

- 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 intialized.
- 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 s struct.- There is not 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.

Submitted By: Anonymous | Created On: 5/16/2009 4:38:17 PM



Post your Answer
Your answer will be first reviewed by our administrator before it appears on the site.

Your Answer:


 
Display Name:





By clicking on Submit button you agree to the Terms of Service agreement.




Copyright © 2018 CrazyEngico.com. All rights reserved.
CrazyEngico.com is not responsible for the content and CrazyEngico.com does not evaluate or guarantee the accuracy of any CrazyEngico.com content.
Please read our terms of service agreement before using this site.

feedback