why sturcture ? why class?why you prefer structure and in
which cases u go for class?



why sturcture ? why class?why you prefer structure and in which cases u go for class?..

Answer / supraja

Class
-->It is reference type
-->The values allocated in heap
-->Can have constructors, properties, methods
-->Abstract and sealed are possible
-->We cannot have parameter less constructor
-->We can overload constructors
-->Reference type
-->Supports data members, code members (methods) and events
-->Supports inheritance
-->Preferable when you need to initialize one or more
members upon creation
-->Can have parameterized constructors
-->More flexible, unlimited event handling support

Structure
-->It is value type
-->The values allocated in stack
-->Can have constructors, properties, methods
-->Abstract and sealed are not possible
-->By default public
-->We cannot have parameter less constructor
-->We can overload constructors
-->Value type
-->Supports data members, code members (methods) and events
-->Can not inherit
-->Preferable when you perform large number of operations
on each instance
-->Can not control initialization using structure variable
-->Less flexible, limited event handling support

Is This Answer Correct ?    4 Yes 6 No

Post New Answer

More C Sharp Interview Questions

How do I create a multi language, multi file assembly?

0 Answers  


Explain About .Net remoting

0 Answers   Digital GlobalSoft,


Is linkedhashset synchronized?

0 Answers  


why delegate is type safe?

0 Answers   IBS,


Consider the following pieces of C# code: a. interface I1 {/*......*/} interface I2 {/*......*/} struct Point : I1,I2 {/* ..... */} b. struct Book{ int bookId; struct Book b; } c. using M=Mystruct; struct MyStruct{ int id; } class MyClass{ static void Main(string[] args){ M m = new M(); } } d. struct Sample{ Sample ref x; } Which of the above are correct? Choose one of the options below. a, c and d are right a only right a and c are right d only wrong None of the listed options

3 Answers  






What is a verbatim string literal and why do we use it?

0 Answers  


C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?

3 Answers   Visual Soft,


what is the purpose of using statement in c#

0 Answers   Cognizant,


What is the example of predicate?

0 Answers  


What is the implicit name and type of the parameter that gets passed into the class set method?

0 Answers  


What is appdomain in c#?

0 Answers  


What?s the difference between the System.Array.CopyTo() and System.Array.Clone()?

3 Answers  


Categories