Hi,
Got a bit of a fun one - but first the code...
The get part won't work (the compiler complains that value isn't valid).
Is there a way using a get that I can return either person[value] or job[value]?
I've tried other methods to get this to work, but nothing seems to be happy.
Thanks
Paul
Got a bit of a fun one - but first the code...
Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace IndexedClass
{
class Program
{
static void Main() // remove the string args[] - unless you're passing stuff in it's pointless!
{
peoplejobs folks = new peoplejobs();
folks.Person = "Jones";
folks.Job = "waiter";
folks.Person = "Smith";
folks.Job = "fitter";
Console.WriteLine(folks.Person[0] + "is a " + folks.Job[0]);
Console.WriteLine(folks.Person[1] + "is a " + folks.Job[1]);
Console.ReadKey();
}
}
public class peoplejobs
{
List <string> person = new List<string>();
List <string> job = new List<string>();
public string Person
{
set { person.Add(value); }
get { return person[value]; }
}
public string Job
{
set {job.Add(value);}
get { return job[value]; }
}
}
}
Is there a way using a get that I can return either person[value] or job[value]?
I've tried other methods to get this to work, but nothing seems to be happy.
Thanks
Paul
Comment