Trzeba po prostu po swojemu zaimplementować indekser, np. tak:
using System;
using System.Collections.Generic;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
List<Student> studęty = new List<Student>();
studęty.Add(new Student("Zenon", "Dentka", "1234"));
studęty.Add(new Student("Franek", "Kimono", "7894556"));
foreach (var s in studęty)
{
Console.WriteLine(s);
}
studęty[0][1] = "Maggajwer";
studęty[1][0] = "Hermenegilda";
foreach (var s in studęty)
{
Console.WriteLine(s);
}
Console.ReadLine();
}
}
class Student
{
public string Imię { get; set; }
public string Nazwisko { get; set; }
public string NumerIndeksu { get; set; }
public Student(string imię, string nazwisko, string numerIndeksu)
{
this.Imię = imię;
this.Nazwisko = nazwisko;
this.NumerIndeksu = numerIndeksu;
}
public string this[int index]
{
get
{
switch (index)
{
case 0:
return this.Imię;
case 1:
return this.Nazwisko;
case 2:
return this.NumerIndeksu;
default:
throw new IndexOutOfRangeException("Nie ma tylu właściwości!");
}
}
set
{
switch (index)
{
case 0:
this.Imię = value;
break;
case 1:
this.Nazwisko = value;
break;
case 2:
this.NumerIndeksu = value;
break;
default:
throw new IndexOutOfRangeException("Nie ma tylu właściwości!");
}
}
}
public override string ToString()
{
return string.Format("Student: {0} {1}, numer indeksu: {2}", this.Imię, this.Nazwisko, this.NumerIndeksu);
}
}
}
Ale w 99% przypadków (np. w moim przykładzie) to jest bez sensu. Jesteś pewien, że czegoś takiego potrzebujesz?