Re: Enumeration in C sharp
Enumeration is known as enum(keyword). The enum is usually under a value type which is a set of related named constants and often referred to as an enumerator list. Enumeration are assume to be strong typed constants.
Syntax:
enum identifier (:base-type)
{
enumerator-list
}
Enum will allow code to see a lot cleaner and easier to read by getting rid of 'magic numbers'. The enum will get the numbers which have a purpose within a module of code, but make the code harder to read.
Re: Enumeration in C sharp
Enumeration is achieved through using the enum keyword. They are assume as strong type constants. The Enum's are overall a unique type which will allow you to assign symbolic names to integral values. And in C sharp, this enum are strongly typed, and it means that one type will not be implicitly assigned to an enum of another type even though the underlying value of their members are the same. Example:
enum Direction
{
North,
East,
South,
West
}
Re: Enumeration in C sharp
According to me, in the C sharp, the enum(enumeration) is 'a unique(distinct) set of value types which will declare a set of named constants.' And when you do programming in C sharp, you will have to declare an enum through the enum keyword. Enums are strongly typed constants. Example:
public enum Country
{
India,
USA,
Russia,
SriLanka
}
Re: Enumeration in C sharp
I personally think the enumeration is most valuable/essential function in C sharp. They are very useful. In the situation, where we need to set a related numbers in a program, and assume the replacing of that numbers with enum's. Due to this, the program will be more readable and type safe. Listing 17-1 contains an enum definition and code that uses that enum in a switch statement. In-replace of using the numbers 0, 1, 2, and 3 in the switch statement, the code will become more meaningful through the use of the Volume enum. Hope your problem will be fix.
Re: Enumeration in C sharp
My knowledge about C sharp says that, the enums are considered as strong typed constants. The Enum's are essentially unique types which will allow you to assign symbolic names to integral values. I would give you the simple example of how does enumeration works and how to use it:
public enum demoenum
{
X = 1,
Y = 2,
Z = X + Y,
A = X * Z + 33
}
public class EnumerationDemo
{
public static void Member(demoenum d1)
{
// do some processing here
}
public static void Main()
{
demoenum d1 = 0;
Member(d1);
}
}
Hope you will be able to understand all about enumeration.