Sample Coding Day 6 - Indexer example

2 views
Skip to first unread message

Nuwan

unread,
Jan 21, 2006, 2:20:35 AM1/21/06
to sliit-mcsd
class ExamMarks {
private int marks1, marks2, marks3;

public ExamMarks(int m1, int m2, int m3) {
marks1 =m1;
marks2 = m2;
marks3 = m3;
}

public int this[int i] {
get {
if (i==1)
return marks1;
else if (i == 2)
return marks2;
else
return marks3;
}
}

}

class sample {

public static void Main() {
ExamMarks mrks = new ExamMarks(45, 90, 78);
System.Console.WriteLine("{0} {1} {2}",
mrks[1], mrks[2], mrks[9]);

System.Console.WriteLine(25 & 8);
}
}

Reply all
Reply to author
Forward
0 new messages