Académique Documents
Professionnel Documents
Culture Documents
Introduction
C# is a simple & powerful object-oriented programming language developed by
Microsoft. C# can be used to create various types of applications, such as web,
windows, console applications or other types of applications using Visual studio.
Dotnet framework:
Version .NET Framework Visual Studio Important Features
C# 1.0 .NET Framework 1.0/1.1 Visual Studio .NET 2002
Basic features
C# 3.0 .NET Framework 3.0\3.5 Visual Studio 2008 Implicitly typed local variables
Object and collection initializers
Auto-Implemented properties
Anonymous types
Extension methods
Query expressions
Lambda expressions
Expression trees
Partial Methods
C# 4.0 .NET Framework 4.0 Visual Studio 2010 Dynamic binding (late binding)
Named and optional arguments
Generic co- and contravariance
Embedded interop types
Dotnet Core
2.1 Long-term
2018-05-30 2021-08-21 Visual Studio 2017
support
Click on https://visualstudio.microsoft.com/
Step2: Select Community 2019, and you will find setup file in the downloads
Step3: You can use it to customize your installation by selecting the feature sets—or
workloads—that you want. Here's how. And click on install/modify.
After the new workloads and components are installed, choose Launch.
https://docs.microsoft.com/en-us/visualstudio/install/install-visual-studio?view=vs-2019
Step4:
C# Keywords
C# contains reserved words, that have special meaning for the compiler.
These reserved words are called "keywords". Keywords cannot be used as a
name (identifier) of a variable, class, interface, etc.
Modifier Keywords
Modifier keywords are certain keywords that indicate who can modify types
and type members. Modifiers allow or prevent certain parts of programs from
being modified by other parts.
Modifier keywords
Abstract
Async
Const
event
extern
new
override
partial
readonly
Modifier keywords
sealed
static
unsafe
virtual
volatile
public The Public modifier allows any part of the program in the same assembly or another assembly to
access the type and its members.
private The Private modifier restricts other parts of the program from accessing the type and its members.
Only code in the same class or struct can access it.
internal The Internal modifier allows other program code in the same assembly to access the type or its
members. This is default access modifiers if no modifier is specified.
protected The Protected modifier allows codes in the same class or a class that derives from that class to access
the type or its members.
Statement Keywords
Statement keywords are related to program flow.
Statement Keywords
if
else
switch
case
do
for
Statement Keywords
foreach
in
while
break
continue
default
goto
return
yield
throw
try
catch
finally
checked
unchecked
fixed
lock
params
ref
out
Namespace Keywords
These keywords are applied with namespace and related operators.
Namespace Keywords
using
. operator
:: operator
extern alias
Operator Keywords
Operator keywords perform miscellaneous actions.
Operator Keywords
as
await
is
new
sizeof
typeof
stackalloc
checked
unchecked
Access Keywords
Access keywords are used to access the containing class or the base class of
an object or class.
Access keywords
base
this
Literal Keywords
Literal keywords apply to the current instance or value of an object.
Literal Keywords
null
false
true
value
void
Type Keywords
Type keywords are used for data types.
Type keywords
bool
byte
char
class
decimal
double
enum
float
int
long
sbyte
short
string
struct
uint
ulong
ushort
Contextual Keywords
Contextual keywords are considered as keywords, only if used in certain
contexts. They are not reserved and so can be used as names or identifiers.
Contextual Keywords
add
var
dynamic
global
set
value
Contextual keywords are not converted into blue color (default color for
keywords in visual studio) when used as an identifier in Visual Studio. For
example, var in the below figure is not in blue color whereas color of this is
blue color. So var is a contextual keyword.
C# Keywords
Query Keywords
Query keywords are contextual keywords used in LINQ queries.
Query Keywords
from
where
select
group
into
orderby
Query Keywords
join
let
in
on
equals
by
ascending
descending
1.Press F5
2.Click on debugger.
Or
Click on F9 at the statement.
Or
Variable
The variable in C# is nothing but a name given to a data value.
Syntax:iable Syntax:
int i, j, k, l = 0;
int j = i;
Data Types
Example: bool
Byte,char,decimal,double,enum,float,int,long,sbyte,short,struct,uint,ulong,ushort.
Reference Type:
Unlike value types, a reference type doesn't store its value directly. Instead, it
stores the address where the value is being stored. In other words, a reference
type contains a pointer to another memory location that holds the data.
String, All arrays, even if their elements are value types, Class, Delegates.
Operators
Conditional statements
if Statement
C# provides many decision making statements that help the flow of the C#
program based on certain logical conditions. C# includes the following decision
making statements.
1. if statement
2. if-else statement
3. switch statement
4. Ternary operator :?
Here, you will learn about the if statements.
Syntax:
if(boolean expression)
{
// execute this code block if expression evalutes to true
}
The if statement contains boolean expression inside brackets followed by a
single or multi line code block. At runtime, if a boolean expression is evalutes
to true then the code block will be executed.
Example: if condition
if(true)
{
Console.WriteLine("This will be displayed.");
}
if(false)
{
Console.WriteLine("This will not be displayed.");
}
As mentioned above, if statement can contain boolean expression. An
expression which returns either true or false. Following example uses logical
expression as a condition:
Example: if condition
int i = 10, j = 20;
if (i > j)
{
Console.WriteLine("i is greater than j");
}
if (i < j)
{
Console.WriteLine("i is less than j");
}
if (i == j)
{
Console.WriteLine("i is equal to j");
}
In the above example, the boolen expression i < j in the second 'if' statement
evalutes to be true, only the second 'if' statement's code block will be
executed. The first and third 'if' condition evalutes to false, so their code blocks
will not be executed.
if-else Statement
C# also provides for a second part to the if statement, that is else . The else
statement must follow if or else if statement. Also, else statement can appear
only one time in a if-else statement chain.
Syntax:
if(boolean expression)
{
// execute this code block if expression evalutes to true
}
else
{
// always execute this code block when above if expression is false
}
As you can see in the above syntax, the else stament cannot contain any
expression. The code block that follows else statement will always be
executed, when the 'if' condition evalutes to be false.
Example: if else
int i = 10, j = 20;
if (i > j)
{
Console.WriteLine("i is greater than j");
}
else
{
Console.WriteLine("i is either equal to or less than j");
}
else if Statement
The 'if' statement can also follow an 'else' statement, if you want to check for
another condition in the else part.
Example: else if
static void Main(string[] args)
{
int i = 10, j = 20;
if (i > j)
{
Console.WriteLine("i is greater than j");
}
else if (i < j)
{
Console.WriteLine("i is less than j");
}
else
{
Console.WriteLine("i is equal to j");
}
}
You can use multiple else-if statements in a single 'if' statment chain. Also,
you can remove the curly brackets, when the 'if' block has only one line to
execute:
if (i > j)
Console.WriteLine("i is greater than j");
else if (i < j)
Console.WriteLine("i is less than j");
else if (i == j)
Console.WriteLine("i is equal to j");
Nested if Statements
C# alows nested if else statements. The nested 'if' statement makes the code
more readable.
if (i > 0)
{
if (i <= 100)
{
Console.WriteLine("i is positive number less than 100");
}
else
{
Console.WriteLine("i is positive number greater than 100");
}
}
C# - Ternary operator ?:
C# includes a special type of decision making operator '?:' called the ternary
operator.
Variable Syntax:
Boolean Expression ? First Statement : Second Statement
As you can see in the above syntax, ternary operator includes three parts.
First part (before ?) includes conditional expression that returns boolean value
true or false. Second part (after ? and before :) contains a statement which
will be returned if the conditional expression in the first part evalutes to true.
The third part includes another statement which will be returned if the
conditional expression returns false.
Ternary operator returns a value or expression included in the second or third part
of it. It does not execute the statements.
var result = x > y ? "x is greater than y" : "x is less than or equal to y";
Console.WriteLine(result);
The ternary operator can return a value of any data type. So it is advisable to
store it in implicitly typed variable - var.
Console.WriteLine(result);
Ternary operator can also be used instead of if-else statement. The above
example can be written using if-else statement as shown below.
if (x > y)
result = x;
else if (x < y)
result = y;
Console.WriteLine(result);
C# - switch
C# includes another decision making statement called switch. The switch
statement executes the code block depending upon the resulted value of an
expression.
Syntax:
switch(expression)
{
case <value1>
// code block
break;
case <value2>
// code block
break;
case <valueN>
// code block
break;
default
// code block
break;
}
As per the syntax above, switch statement contains an expression into
brackets. It also includes multiple case labels, where each case represents a
particular literal value. The switch cases are seperated by a break keyword
which stops the execution of a particular case. Also, the switch can include a
default case to execute if no case value satisfies the expression.
Case label in switch must be unique. It can be bool, char, string, integer, enum, or
corresponding nullable type.
Example: switch
int x = 10;
switch (x)
{
case 5:
Console.WriteLine("Value of x is 5");
break;
case 10:
Console.WriteLine("Value of x is 10");
break;
case 15:
Console.WriteLine("Value of x is 15");
break;
default:
Console.WriteLine("Unknown value");
break;
}
The switch statement can include expression or variable of any data type such
as string, bool, int, enum, char etc.
switch (statementType)
{
case "if.else":
Console.WriteLine("if...else statement");
break;
case "ternary":
Console.WriteLine("Ternary operator");
break;
case "switch":
Console.WriteLine("switch statement");
break;
}
Goto in switch:
The switch case can use goto to jump over a different case.
switch (statementType)
{
case "DecisionMaking":
Console.Write(" is a decision making statement.");
break;
case "if.else":
Console.Write("if-else");
break;
case "ternary":
Console.Write("Ternary operator");
break;
case "switch":
Console.Write("switch statement");
goto case "DecisionMaking";
}
Nested switch:
Nested switch statments are allowed in C# by writing inner switch statement
inside a outer switch case.
switch (j)
{
case 5:
Console.WriteLine(5);
switch (j - 1)
{
case 4:
Console.WriteLine(4);
switch (j - 2)
{
case 3:
Console.WriteLine(3);
break;
}
break;
}
break;
case 10:
Console.WriteLine(10);
break;
case 15:
Console.WriteLine(15);
break;
default:
Console.WriteLine(100);
break;
}
C# - for loop
The for keyword indicates a loop in C#. The for loop executes a block of
statements repeatedly until the specified condition returns false.
Syntax:
for (variable initialization; condition; steps)
{
//execute this code block as long as condition is satisfied
}
As per the syntax above, the for loop contains three parts: initialization,
conditional expression and steps, which are separated by a semicolon.
1. variable initialization: Declare & initialize a variable here which will be used in
conditional expression and steps part.
2. condition: The condition is a boolean expression which will return either true
or false.
3. steps: The steps defines the incremental or decremental part
As you can see in the above example, first step is to declare & initialize an int
type variable. The second step is to check the condition. The third step is to
execute the code block if the 'if' condition returns true. The fourth step is to
increment the int variable and last step is to eveluate the condition again and
repeat the steps.
It is not necessary to put the initialization, condition and steps into brackets.
You can initialize a variable before the 'for' loop, and the condition and steps
can be defined inside the for loop.
for(;;)
{
if (i < 10)
{
Console.WriteLine("Value of i: {0}", i);
i++;
}
else
break;
}
The steps part in a for loop can either increase or decrease the value of a
variable.
Syntax:
While(boolean expression)
{
//execute code as long as condition returns true
}
As per the while loop syntax, the while loop includes a boolean expression as
a condition which will return true or false. It executes the code block, as long
as the specified conditional expression returns true. Here, the initialization
should be done before the loop starts and increment or decrement steps
should be inside the loop.
i++;
}
In the above example, while loop inclues an expression i < 10 . Inside while
loop, value of i increased to 1 (using i++ ). So, the above while loop will be
executed till the value of i will be 10.
Use the break keyword to exit from a while loop as shown below.
while (true)
{
Console.WriteLine("Value of i: {0}", i);
i++;
if (i > 10)
break;
}
Nested while loop:
Nested while loop is allowed in C#
while (i < 2)
{
Console.WriteLine("Value of i: {0}", i);
int j = 1;
i++;
while (j < 2)
{
Console.WriteLine("Value of j: {0}", j);
j++;
}
}
C# - do while
The do-while loop is the same as a 'while' loop except that the block of code
will be executed at least once, because it first executes the block of code and
then it checks the condition.
Syntax:
do
{
//execute code block
} while(boolean expression);
As per the syntax above, do-while loop starts with the 'do' keyword followed
by a code block and boolean expression with 'while'.
do
{
Console.WriteLine("Value of i: {0}", i);
i++;
do
{
Console.WriteLine("Value of i: {0}", i);
i++;
if (i > 5)
break;
} while (true);
Nested do-while
The do-while loop can be used inside another do-while loop.
do
{
Console.WriteLine("Value of i: {0}", i);
int j = i;
i++;
do
{
Console.WriteLine("Value of j: {0}", j);
j++;
An array is a special type of data type which can store fixed number of values
sequentially using special syntax.
Array Representation
As you can see in the above figure, index is a number starting from 0, which
stores the value. You can store a fixed number of values in an array. Array
index will be increased by 1 sequentially till the maximum specified array size.
Array Declaration
An array can be declare using a type name followed by square brackets [].
// defining array with size 5 and adding values at the same time
int[] intArray2 = new int[5]{1, 2, 3, 4, 5};
In the above example, the first statement declares & initializes int type array
that can store five int values. The size of the array is specified in square
brackets. The second statement, does the same thing, but it also assignes
values to each indexes in curley brackets { }. The third statement directly
initializes an int array with the values without giving any size. Here, size of an
array will automatically be number of values.
Initialization without giving size is NOT valid. For example, the following
example would give compile time error.
Late Initialization
Arrays can be initialized after declaration. It is not necessary to declare and
initialize at the same time using new keyword. Consider the following example.
intArray[0] = 10;
intArray[1] = 20;
intArray[2] = 30;
intArray[3] = 40;
intArray[4] = 50;
In the same way, you can retrieve values at a particular index, as below:
intArray[2]; //returns 30
Use a for loop to access the values from all the indexes of an array by using
length property of an array.
foreach(var i in intArray)
Console.WriteLine(i);
Property Description
Array.Sort(intArr);
Array.Reverse(intArr);
You can create an instance of an Array that starts with index 1 (not default
starting index 0) using Array class as shown below:
array.SetValue(1, 1);
array.SetValue(2, 2);
array.SetValue(3, 3);
array.SetValue(4, 4);
array.SetValue(5, 5);
C# Collection:
We have learned about an array in the previous section. C# also includes
specialized classes that hold many values or objects in a specific series, that
are called 'collection'.
The System.Collections namespace includes the interfaces and classes for the
non-generic collections.
C# Collections
So, all the built-in collection classes and custom collection classes must
implement IEnumerator and IEnumerable interfaces for easy iteration using
foreach loop.
ICollection: The ICollection interface is the base interface for all the collections
that defines sizes, enumerators, and synchronization methods for all non-
generic collections. The Queue and Stack collection implement ICollection
inferface.
IList: The IList interface includes properties and methods to add, insert,
remove elements in the collection and also individual element can be accessed
by index. The ArrayList and BitArray collections implement IList interface.
IDictionary: The IDictionary interface represents a non-generic collection of
key/value pairs. The Hashtable and SortedList implement IDictionary interface
and so they store key/value pairs.
As you can see from the diagram, ArrayList, BitArray, Hashtable, SortedList,
Queue, and Stack collections implement different interfaces and so, they are
used for the different purposes.
Non-generic
Collections Usage
ArrayList ArrayList stores objects of any type like an array. However, there is no need to specify the size of the
ArrayList like with an array as it grows automatically.
SortedList SortedList stores key and value pairs. It automatically arranges elements in ascending order of key by
default. C# includes both, generic and non-generic SortedList collection.
Stack Stack stores the values in LIFO style (Last In First Out). It provides a Push() method to add a value and Pop()
& Peek() methods to retrieve values. C# includes both, generic and non-generic Stack.
Queue Queue stores the values in FIFO style (First In First Out). It keeps the order in which the values were added. It
provides an Enqueue() method to add values and a Dequeue() method to retrieve values from the collection.
C# includes generic and non-generic Queue.
Hashtable Hashtable stores key and value pairs. It retrieves the values by comparing the hash value of the keys.
BitArray BitArray manages a compact array of bit values, which are represented as Booleans, where true indicates
that the bit is on (1) and false indicates the bit is off (0).
C# - ArrayList
ArrayList is a non-generic type of collection in C#. It can contain elements of
any data types. It is similar to an array, except that it grows automatically as
you add items in it. Unlike an array, you don't need to specify the size of
ArrayList.
Capacity Gets or sets the number of elements that the ArrayList can contain.
IsFixedSize Gets a value indicating whether the ArrayList has a fixed size.
Methods Description
Insert()/InsertRange() Insert() method insert a single elements at the specified index in ArrayList.
InsertRange() method insert all the elements of the specified collection starting from specified
index in ArrayList.
Remove()/RemoveRange() Remove() method removes the specified element from the ArrayList.
RemoveRange() method removes a range of elements from the ArrayList.
RemoveAt() Removes the element at the specified index from the ArrayList.
Contains Checks whether specified element exists in the ArrayList or not. Returns true if exists otherwise
false.
GetRange Returns specified number of elements from specified index from ArrayList.
IndexOf Search specified element and returns zero based index if found. Returns -1 if element not found.
//Or
for(int i = 0 ; i< myArryList.Count; i++)
Console.WriteLine(myArryList[i]);
Example: Insert()
IList myArryList = new ArrayList();
myArryList.Add(1);
myArryList.Add("Two");
myArryList.Add(3);
myArryList.Add(4.5);
Use the ArrayList.InsertRange() method to insert all the values from another
collection into ArrayList at the specfied index. Please note that
the InsertRange() method only available in the ArrayList class but not in IList .
So, it can only be use with the variable of type ArrayList.
Example: InsertRange()
IList arryList1 = new ArrayList();
arryList1.Add(100);
arryList1.Add(200);
arryList2.InsertRange(2, arryList1);
Example: Remove()
IList arryList1 = new ArrayList();
arryList1.Add(100);
arryList1.Add(200);
arryList1.Add(300);
Use the IList.RemoveAt() method to remove an element from the specified index
location.
Example: RemoveAt()
IList arryList1 = new ArrayList();
arryList1.Add(100);
arryList1.Add(200);
arryList1.Add(300);
Example: RemoveRange()
ArrayList arryList1 = new ArrayList();
arryList1.Add(100);
arryList1.Add(200);
arryList1.Add(300);
ArrayList Sorting
The ArrayList class includes Sort() and Reverse() method. The Sort() method
arranges elements in ascending order. However, all the elements should have
same data type so that it can compare with default comparer otherwise it will
throw runtime exception.
The Reverse() method arranges elements in reverse order. Last element at zero
index and so on.
Console.WriteLine("Original Order:");
arryList1.Reverse();
Console.WriteLine("Reverse Order:");
arryList1.Sort();
Console.WriteLine("Ascending Order:");
Example: Contains()
IList myArryList = new ArrayList();
myArryList.Add(100);
myArryList.Add("Hello World");
myArryList.Add(300);
Console.WriteLine(myArryList.Contains(100)); // true
C# - Hashtable
C# includes Hashtable collection in System.Collections namespace, which is
similar to generic Dictionary collection. The Hashtable collection stores key-
value pairs. It optimizes lookups by computing the hash code of each key and
stores it in a different bucket internally and then matches the hash code of
the specified key at the time of accessing values.
C# Hashtable
Important Propertis and Methods of Hashtable
Property Description
Item Gets or sets the value associated with the specified key.
Methods Usage
Add Adds an item with a key and value into the hashtable.
Remove Removes the item with the specified key from the hashtable.
Example: Add()
Hashtable ht = new Hashtable();
ht.Add(1, "One");
ht.Add(2, "Two");
ht.Add(3, "Three");
ht.Add(4, "Four");
ht.Add(5, null);
ht.Add("Fv", "Five");
ht.Add(8.5F, 8.5);
You can also assign key and value at the time of initialization using object
initializer syntax:
Example: Add()
Hashtable ht = new Hashtable()
{
{ 1, "One" },
{ 2, "Two" },
{ 3, "Three" },
{ 4, "Four" },
{ 5, null },
{ "Fv", "Five" },
{ 8.5F, 8.5 }
};
Hashtable can include all the elements of Dictionary as shown below.
Example: Add()
Dictionary<int, string> dict = new Dictionary<int, string>();
dict.Add(1, "one");
dict.Add(2, "two");
dict.Add(3, "three");
Note : Add() will throw an exception if you try to add a key that already exists in the
Hashtable. So always check the key using the Contains() or ContainsKey() method
before adding a key-value pair into the Hashtable.
Access Hashtable
You can retrive the value of an existing key from the Hashtable using indexer.
Please note that the hashtable indexer requires a key.
ht.Add(1, "One");
ht.Add(2, "Two");
ht.Add(3, "Three");
ht.Add(4, "Four");
ht.Add("Fv", "Five");
ht.Add(8.5F, 8.5F);
Hashtable has a Keys and a Values property that contain all the keys and
values respectively. You can use these properties to get the keys and values.
Console.WriteLine("***All Values***");
foreach (var value in ht.Values)
Console.WriteLine("Value:{0}", value);
Example: Remove()
Hashtable ht = new Hashtable()
{
{ 1, "One" },
{ 2, "Two" },
{ 3, "Three" },
{ 4, "Four" },
{ 5, null },
{ "Fv", "Five" },
{ 8.5F, 8.5 }
};
Example: Contains
Hashtable ht = new Hashtable()
{
{ 1, "One" },
{ 2, "Two" },
{ 3, "Three" },
{ 4, "Four" }
};
Example: Clear()
Hashtable ht = new Hashtable()
{
{ 1, "One" },
{ 2, "Two" },
{ 3, "Three" },
{ 4, "Four" },
{ 5, null },
{ "Fv", "Five" },
{ 8.5F, 8.5 }
};
Generics in C#
Generics allow for designing a classes and methods whose types are specified only at the time of
declaration and instantiation. This enables development of universal classes and methods that help in
improving performance, productivity and type-safety.
A generic class can be defined using angle brackets <>. For example, the
following is a simple generic class with a generic member variable, generic
method and property.
Example: Generic
class MyDerivedClass : MyGenericClass<string>
{
//implementation
}
If you want the derived class to be generic then no need to specify type for
the generic base class.
Example: Constraints
class MyGenericClass<T> where T: class
{
// Implementation
}
Generic Delegates
As you have already learned in the previous section, the delegate defines the
signature of the method which it can invoke. A generic delegate can be defined
the same way as delegate but with generic type.
For example, consider the following generic delegate that takes two generic
parameters.
Console.WriteLine(sum(10, 20));
Console.WriteLine(conct("Hello","World!!"));
}
In the above example, add delegate is generic. In the Main() method, it has
defined add delegate of int type variable sum. So it can point to the
AddNumber() method which has int type parameters. Another variable of add
delegate uses string type, so it can point to the Concate method. In this way,
you can use generic delegates for different methods of different types of
parameters.
Note:
A generic delegate can point to methods with different parameter types. However,
the number of parameters should be the same.
Interface
Abstract class
Class
Method
Static method
Property
Event
Delegates
Operator
Advantages of Generics
1. Increases the reusability of the code.
2. Generic are type safe. You get compile time errors if you try to use a different
type of data than the one specified in the definition.
3. Generic has a performance advantage because it removes the possibilities of
boxing and unboxing.
return genericMemberVariable;
}
return genericMemberVariable;
}
Constraint Description
where T: <base class name> Type must be or derive from the specified base class
where T: U Type supplied for T must be or derive from the argument supplied for U.
Multiple constraints:
A generic class can have multiple constraints as shown below.
Multiple constraints:
class MyGenericClass<T, U> where T: class where U:struct
{
...
}
Method constraint:
class MyGenericClass<T> where T: class
{
public T genericMethod<U>(T genericParameter, U anotherGenericType) where U: struct
{
Console.WriteLine("Generic Parameter of type {0}, value {1}",
typeof(T).ToString(),genericParameter);
Console.WriteLine("Return value of type {0}, value {1}", typeof(T).ToString(),
genericMemberVariable);
return genericMemberVariable;
}
}
Thus, constraints can be applied on generic types.
C# - enum
In C#, enum is a value type data type. The enum is used to declare a list of
named integer constants. It can be defined using the enum keyword directly
inside a namespace, class, or structure. The enum is used to give a name to
each constant so that the constant integer can be referred using its name.
Example: enum
enum WeekDays
{
Monday = 0,
Tuesday =1,
Wednesday = 2,
Thursday = 3,
Friday = 4,
Saturday =5,
Sunday = 6
}
Console.WriteLine(WeekDays.Friday);
Console.WriteLine((int)WeekDays.Friday);
By default, the first member of an enum has the value 0 and the value of each
successive enum member is increased by 1. For example, in the following
enumeration, Monday is 0, Tuesday is 1, Wednesday is 2 and so forth.
Example: enum
enum WeekDays
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
}
Console.WriteLine((int)WeekDays.Monday);
Console.WriteLine((int)WeekDays.Friday);