Getting an error about a non static field that is instantiated as a Hastable
I've tried everything I can think of, but it still comes back with following error:
Error 1 An object reference is required for the non-static field, method, or property 'MortimerPhonesEmployees.TestHarness.employees' C:\Users\Tom Magaro\Documents\Visual Studio 2008\Projects\Collections\MortimerPhonesEmployees\ TestHarness.cs 47 29 MortimerPhonesEmployees.
Here is the code. I've bolded and underlined the problem field.
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace MortimerPhonesEmployees
{
classTestHarness
{
Hashtable employees = newHashtable(31);
publicstaticvoid Run()
{
EmployeeID idMortimer = newEmployeeID("B001");
EmployeeData mortimer = newEmployeeData(idMortimer, "Mortimer",
100000.00M);
EmployeeID idArabel = newEmployeeID("W234");
EmployeeData arabel = newEmployeeData(idArabel, "Arabel Jones",
10000.00M);
while (true)
{
try
{
Console.Write("Enter employee ID (format:A999, X to exit)>");
string userinput = Console.ReadLine();
userinput = userinput.ToUpper();
if (userinput == "X")
return;
EmployeeID id = newEmployeeID(userinput);
DisplayData(id);
}
catch (Exception e)
{
Console.WriteLine("Exception occurred. Did you use the correct" +
"format for the employee ID?");
Console.WriteLine(e.Message);
Console.WriteLine();
}
Console.WriteLine();
}
}
privatestaticvoid DisplayData(EmployeeID id)
{
object empobj = employees[id];
if (empobj != null)
{
EmployeeData employee = (EmployeeData)empobj;
Console.WriteLine("Employee: " + employee.ToString());
}
else
Console.WriteLine("Employee not found: ID = " + id);
}
}
}
I am running on vs2008 but I can't afford the book for it.
any help would be appreciated.
Thanx,
Tom
__________________
Thomas G Magaro
Last edited by flashmanTom; April 1st, 2010 at 02:59 PM..
|