using
System;
class
IndexerPOC
{
private
string
[] val =
new
string
[4];
private
string
[] indices={
"username"
,
"password"
,
"email"
,
"Book"
};
public
string
this
[
string
index]
{
get
{
return
val[Array.IndexOf(indices,index)];
}
set
{
val[ Array.IndexOf(indices,index)] = value;
}
}
}
class
Program {
public
static
void
Main() {
IndexerPOC ic =
new
IndexerPOC();
ic[
"username"
] =
"user12"
;
ic[
"password"
] =
"12345"
;
ic[
"Book"
]=
"CSHARP"
;
Console.Write(
"Printing values stored in objects used as arrays\n"
);
Console.WriteLine(
"UserName = {0}"
, ic[
"username"
]);
Console.WriteLine(
"Password = {0}"
, ic[
"password"
]);
Console.WriteLine(
"Email = {0}"
, ic[
"email"
]);
Console.WriteLine(
"Book = {0}"
, ic[
"Book"
]);
}
}