OOPS CONCEPT IN C#
Generic Class
Generic Class is a class whose instances can work on
different types of data. Not only methods classes also can be created as
generic classes.
Enumeration:
An
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.
enum <enum_name>
{
enumeration list
};
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();
}
}
}
Const
A constant member is defined at compile time and cannot be
changed at runtime. Constants are declared as a field, using the const keyword
and must be initialized as they are declared.
For example;
public class MyClass
{
public const double
PI = 3.14159;
}
PI cannot be changed in the application anywhere else
in the code as this will cause a compiler error
Readonly
public class MyClass
{
public readonly double
PI = 3.14159;
}