Topic: enumeration
Enumeration is a set of named integer constants. An enumerated type is declared using the enumkeyword.
C# enumerations are value data type. In other words, enumeration contains its own values and cannot inherit or cannot pass inheritance.
Declaring enum Variable
The general syntax for declaring an enumeration is:
enum <enum_name>
{
enumeration list
};
For example:
enum Days { Sun, Mon, tue, Wed, thu, Fri, Sat };
Example:
using System;
namespace EnumApplication
{
class EnumProgram
{
enum Days { Sun, Mon, tue, Wed, thu, Fri, Sat };
static void Main(string[] args)
{
int WeekdayStart = (int)Days.Mon;
int WeekdayEnd = (int)Days.Fri;
Console.WriteLine("Monday: {0}", WeekdayStart);
Console.WriteLine("Friday: {0}", WeekdayEnd);
Console.ReadKey();
}
}
}
When the above code is compiled and executed, it produces the following result:
Monday: 1
Friday: 5
Topic: Partial
Partial used to declare two different classes with same name to make as one whole class. It is done with the keyword “partial” in front.
Example:
Переглядів: 169 |