Reference type: Class
Structure versus Class
A structure store its data, we can create objects of a struct similar to a class.For Example, it can have methods, field, properties,and support static methods. But a structure does not support static class, inheritance and this can also not have default constructor while a class support inheritance, static class and default constructor.
When we create a struct, the variable that we assigned include real data of the struct. If we assigned a new variable, this is a copy .The new and original variable contain two independent copies, so when we modify a variable doesn't affect other.While a class is different if we modify a variable, this affects another because they both reference the same data.
Stack and heap
When we call the new operator on a class, it will be allocated on the heap while the structure is created on the stack, because the structure is simple and light weight.
To create a class and a struct
To create unit test in order to test the different between the struct and class with Toggle breakpoints.
To execute the class
To execute the struct
the result of struct is passed and the class is failed because the name of book no have that be equals
Enum: The enum keyword is used to declare an enumeration, a distinct type that consists of set of named constants called the enumerator list.
It better define a enum directly within a namespace so that all classes in the namespace can access it .However, an enum can also be nested within a class or struct. By default, the first enumerator has the value 0










No hay comentarios:
Publicar un comentario