Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9749697
interface_indexers.cs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
965 B
Subscribers
None
interface_indexers.cs
View Options
// cs_interface_indexers.cs
using
System
;
// Indexer on an interface:
public
interface
IMyInterface
{
// indexer declaration:
int
this
[
int
index
]
{
get
;
set
;
}
}
// Implementing the interface:
class
IndexerClass
:
IMyInterface
{
private
int
[]
myArray
=
new
int
[
100
];
public
int
this
[
int
index
]
// indexer declaration
{
get
{
// Check the index limits
if
(
index
<
0
||
index
>=
100
)
return
0
;
else
return
myArray
[
index
];
}
set
{
if
(
!
(
index
<
0
||
index
>=
100
))
myArray
[
index
]
=
value
;
}
}
}
public
class
MainClass
{
public
static
void
Main
()
{
IndexerClass
b
=
new
IndexerClass
();
// call the indexer to initialize the elements #3 and #5:
b
[
2
]
=
4
;
b
[
5
]
=
32
;
for
(
int
i
=
0
;
i
<=
10
;
i
++
)
{
Console
.
WriteLine
(
"Element #{0} = {1}"
,
i
,
b
[
i
]);
}
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Aug 25, 6:07 PM (1 d, 3 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3464959
Attached To
rPUC universal-ctags debian packaging
Event Timeline
Log In to Comment