
What are the similar features between class and structure in .NET?You would
have heard and experienced several differences between class and structure
in .NET. But do you know that several similarities exist between the two.
If not, then this article is the right place to learn them. Listed below
are the similarities between class and structure: Both
Class and Structure are allowed to implement an interface. Here is an
example to demonstrate it: } Executing
displayMsg from sampleClass Both
Class and Structure contain a default constructor with no arguments. In
the above example, you create instance of Class and Structure using the
following lines of code: Unlike
Class, you cannot explicitly define a no-argument constructor in a Structure.
However both Structure and Class can define constructor with arguments
as shown in the example below: namespace
Application1 { Output of
this code will be: Calling No-Argument
Constructor of sampleClass If you try
to explicitly define a no-argument constructor for a Structure then you
will end Structs
cannot contain explicit parameterless constructors You
can define and use events and delegates in Class as well as Structure.
_______________________________________________________________________
FREE
Subscription
Subscribe
to our mailing list and receive new articles Note
: We never rent, trade, or sell my email lists to Visit
.NET Programming Tutorial Homepage ______________________________________________________ |