Mega Code Archive
Indexers dont have to operate on actual arrays
/*
C#: The Complete Reference
by Herbert Schildt
Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Indexers don't have to operate on actual arrays.
using System;
class PwrOfTwo {
/* Access a logical array that contains
the powers of 2 from 0 to 15. */
public int this[int index] {
// Compute and return power of 2.
get {
if((index >= 0) && (index < 16)) return pwr(index);
else return -1;
}
// there is no set accessor
}
int pwr(int p) {
int result = 1;
for(int i=0; i