Indexer with complex logic
using System;
class MyValue {
private String[] Cards = new String[52];
public String this[int index] {
get {
return Cards[index];
}
set {
Cards[index] = value;
}
}
public String this[String CardName] {
get {
for (int i = 0; i < 52; i++) {
if (Cards[i] == CardName)
return Cards[i];
}
return Cards[0];
}
set {
for (int i = 0; i < 52; i++) {
if (Cards[i] == CardName)
Cards[i] = value;
}
}
}
public MyValue() {
int y = 0;
int i = 0;
while (i < 52) {
for (int x = 0; x < 13; x++) {
switch (y) {
case 0:
Cards[i] = (x + 1) + " A";
break;
case 1:
Cards[i] = (x + 1) + " B";
break;
case 2:
Cards[i] = (x + 1) + " C";
break;
case 3:
Cards[i] = (x + 1) + " D";
break;
}
if (y == 3)
y = 0;
else
y++;
i++;
}
}
}
}
class MyValueClient {
public static void Main() {
MyValue PokerDeck = new MyValue();
String FourOfHearts = PokerDeck["4 of Hearts"];
Console.WriteLine(FourOfHearts);
}
}
|
HTML code for linking to this page:
Related in same category :
-
-
-
-
-
-
-
-
-
-
|