Z
Zach
In the code below two indexed classes are created, viz: People and Jobs.
I would like to merge the two classes into one class called Employee. I
have tried using a List, rather than an array for data, but cannot find
out how to do that. I am aware that I can simply create a List and fill
it with employee objects, but that is not what I am trying to find out
how to do. Could anyone please help me out?
using System;
using System.Collections.Generic;
using System.Text;
namespace IndexedClass
{
class Program
{
static void Main(string[] args)
{
int index_size = 2;
People person = new People(index_size); Jobs job = new
Jobs(index_size);
person[0] = "Jones"; job[0] = "waiter";
person[1] = "Smith"; job[1] = "fitter";
Console.WriteLine(person[0] + "is a " + job[0]);
Console.WriteLine(person[1] + "is a " + job[1]);
Console.ReadKey();
}
}
public struct People
{
private string[] data;
public string this[int Position] { get { return data[Position];
} set { data[Position] = value; } }
public People(int index_size)
{
data = new string[index_size];
}
}
public struct Jobs
{
private string[] data;
public string this[int Position] { get { return data[Position];
} set { data[Position] = value; } }
public Jobs(int index_size)
{
data = new string[index_size];
}
}
}
I would like to merge the two classes into one class called Employee. I
have tried using a List, rather than an array for data, but cannot find
out how to do that. I am aware that I can simply create a List and fill
it with employee objects, but that is not what I am trying to find out
how to do. Could anyone please help me out?
using System;
using System.Collections.Generic;
using System.Text;
namespace IndexedClass
{
class Program
{
static void Main(string[] args)
{
int index_size = 2;
People person = new People(index_size); Jobs job = new
Jobs(index_size);
person[0] = "Jones"; job[0] = "waiter";
person[1] = "Smith"; job[1] = "fitter";
Console.WriteLine(person[0] + "is a " + job[0]);
Console.WriteLine(person[1] + "is a " + job[1]);
Console.ReadKey();
}
}
public struct People
{
private string[] data;
public string this[int Position] { get { return data[Position];
} set { data[Position] = value; } }
public People(int index_size)
{
data = new string[index_size];
}
}
public struct Jobs
{
private string[] data;
public string this[int Position] { get { return data[Position];
} set { data[Position] = value; } }
public Jobs(int index_size)
{
data = new string[index_size];
}
}
}