Posts

Enums in C#

  Enum: v An enum is a collection of named integer constants.   v To create an enum, use the enum keyword.   v Enum is short for "enumerations", which means "specifically listed".   v By default, the associated constant values of enum members are of type int and the approved types are byte, sbyte, short, ushort, uint, long, and ulong.   v Enums are not for end-users, they are meant for developers.   v Enum values are fixed. Enum can be displayed as a string and processed as an integer.   v An explicit cast is required to convert from enum type to an integral type.   v Enums are value types and are created on the stack and not on the heap.   v Enum constants has default values which starts from 0 and incremented to one by one. But we can change the default value.   v We can only assign integral values to the enum names. We should not assign strings as values. Enum in C# can be declared wit...

Structure in C#

  Structure:   v In C#, Structure are used to hold data of various data types into a single variable.   v The struct keyword is used for creating a structure.   v Structure is a value type data type.   v Structures can have methods, fields, indexers, properties, operator, methods, and events etc.   v Structures cannot inherit other structures or classes.   v Structures cannot be used as a base for other structures or classes.   v A structure can implement interfaces.   v Structure members cannot be specified as abstract, sealed virtual, or protected.   v A structure can be instantiated with or without using a new keyword.   v If the New operator is not used, the fields remain unassigned and the object cannot be used until all the fields are initialized.       Structure Declaration & Object Creation: The keyword struct can be used to declare a structure. T...

Properties in C#

  Properties:   v Properties are named members of classes, structures, and interfaces.   v Properties are physical description of an object like name, height and weight etc.   v Member variables or methods in a class or structures are called Fields.   v Properties never used to store any data, it just acts as an interface or medium to transfer the data.   v We use the Properties as they are public data members of a class, but they are actually special methods called accessors.   v The Properties in C# are used as a mechanism to set and get the values of data members of a class outside of that class.   What are Accessors in C#? The Assessors are nothing but special methods which are used to set and get the values from the underlying data member (i.e. variable) of a class. Assessors are of two types. They are as follows:   1.    Set Accessor. 2.    Get Accessor.     ...