newbie static

G

Gigs_

class OverrideProperties
{
public static ArrayList employees = new ArrayList();

public static void PrintEmployeesHourlyCostToCompany()
{
foreach (Employee employee in employees)
{
Console.WriteLine("{0} employee (id={1}) costs {2} per hour",
employee,
employee.EmployeeId,
employee.HourlyCost);
}
}

public static void Main()
{
ContractEmployee c = new ContractEmployee(1, 50, 40);
employees.Add(c);

SalariedEmployee s = new SalariedEmployee(2, 100000, 65);
employees.Add(s);

PrintEmployeesHourlyCostToCompany();

Console.ReadLine();
}
}

why i dont need to use class here in main for static fields?
 
J

Jon Skeet [C# MVP]

why i dont need to use class here in main for static fields?

Sorry, your question isn't very clear. Could you explain what you mean?
What were you expecting to have to do?
 
P

Peter Duniho

[...]
why i dont need to use class here in main for static fields?

Your question is difficult to understand. Are you asking why you can
use the "employees" field in the method Main() without referring to the
class name OverrideProperties?

If so, the answer is simply that the method Main() is also in the class
OverrideProperties, and so the class for the field is implicit, just as
it is for _all_ class members used from within the class that defines
them.

If not, you should reword your question so that it's more clear and
specific about what you're asking.

Pete
 
G

Gigs_

Peter said:
[...]
why i dont need to use class here in main for static fields?

Your question is difficult to understand. Are you asking why you can
use the "employees" field in the method Main() without referring to the
class name OverrideProperties?

If so, the answer is simply that the method Main() is also in the class
OverrideProperties, and so the class for the field is implicit, just as
it is for _all_ class members used from within the class that defines them.

If not, you should reword your question so that it's more clear and
specific about what you're asking.

Pete

yes thats what i mean, i feel so stupid now. its all clear.

i come from python as my first lang.
i just didnt get with new sintax jet and so. too many times i dont see things as
i should

anyway thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top