Skip to main content

Posts

Showing posts with the label Classes

Classes in C#

Classes A class is a construct that enables you to create your own custom types by grouping together variables of other types, methods and events. Classes are declared by using the keyword class followed by the class name and a set of class members surrounded by curly braces. If the class is not declared as static, client code can use it by creating objects or instances which are assigned to a variable. The variable remains in memory until all references to it go out of scope. At that time, the CLR marks it as eligible for garbage collection. If the class is declared as static , then only one copy exists in memory and client code can only access it through the class itself, not an instance variable . Structs Structs are defined by using the struct keyword, for example: public   struct PostalAddress {     // Fields, properties, methods and events go here... } Structs share most of the same syntax as classes, although structs are more limited...