Error CS0051 (Inconsistent accessibility: parameter type 'Job' is less accessible than method 'AddJobs.TotalPay(Job)')

↘锁芯ラ 提交于 2019-12-01 03:06:19

You haven't specified a visibility modifier for your class, which makes it internal.

Try changing this line:

class Job

to this:

public class Job

it means u are accessing a class that is not public.. make the class public like this

public class Job
{

  public Job(string description, double time, double rate)
  {
     Description = description;

     Time = time;

     Rate = rate;
  }

You are right Lasse V. Karlsen you do need to add a public access modifier to the front of the class Job. Over looking the case that a method point "A" is showing the syntax error that indicates that the person was trying to access the private field. When the person should of tried to access the property of the field instead of accessing a field that was a private field.

public static void TotalPay(Job method) { A: A: double totalFee = Job.rate * Job.time; Console.WriteLine("The total fee is: {0}", TotalFee.ToString("C")); } }

There were several different place that had similar errors just follow all of the "A"'s using System;

public class AddJobs { private double totalFee;

                    //A:
public AddJobs(double TotalFee)
{ //A:
    totalFee = TotalFee;
}

public static void Main()
{
    Job job1 = new Job("washing windows", 5.00, 25.00);
    Job job2 = new Job("walking a dog", 3.00, 11.00);
    Job job3;
    job3 = job1 + job2;

    Console.WriteLine("The first job's description: {0} \nTotal time needed to complete the job: {1} hours \nHourly fee: {2} per hour", job1.Description, job1.Time, job1.Rate.ToString("C"));
    TotalPay(job1);

    Console.WriteLine("The second job's description: {0} \nTotal time needed to complete the job: {1} hours \nHourly fee: {2} per hour", job2.Description, job2.Time, job2.Rate.ToString("C"));
    TotalPay(job2);

    Console.WriteLine("The third job's description: {0} \nTotal time needed to complete the job: {1} hours \nHourly fee: {2} per hour", job3.Description, job3.Time, job3.Rate.ToString("C"));
    TotalPay(job3);
}

public static void TotalPay(Job method)
{

    double totalFee = method.Rate * method.Time;
    Console.WriteLine("The total fee is: {0}", totalFee.ToString("C"));
}

}

public class Job {

public Job(string description, double time, double rate)
{
    Description = description;

    Time = time;

    Rate = rate;
}

public static Job operator +(Job first, Job second)
{
    string newDescription = first.Description + " and " + second.Description;

    double newTime = first.Time + second.Time;

    double newRate = (first.Rate + second.Rate) / 2;

    double newTotalFee = newRate * newTime;

    return (new Job(newDescription, newTime, newRate));
}

public string Description { get; set; }
public double Time { get; set; }
public double Rate { get; set; }

}

jonathan
using System;

public class AddJobs
{
    private double totalFee;



    public AddJobs(double TotalFee)
    {
        totalFee = TotalFee;
    }

    public static void Main()
    {
        Job job1 = new Job("washing windows", 5.00, 25.00);
        Job job2 = new Job("walking a dog", 3.00, 11.00);
        Job job3;
        job3 = job1 + job2;

        Console.WriteLine("The first job's description: {0} \nTotal time needed to complete the job: {1} hours \nHourly fee: {2} per hour", job1.Description, job1.Time, job1.Rate.ToString("C"));
        TotalPay(job1);

        Console.WriteLine("The second job's description: {0} \nTotal time needed to complete the job: {1} hours \nHourly fee: {2} per hour", job2.Description, job2.Time, job2.Rate.ToString("C"));
        TotalPay(job2);

        Console.WriteLine("The third job's description: {0} \nTotal time needed to complete the job: {1} hours \nHourly fee: {2} per hour", job3.Description, job3.Time, job3.Rate.ToString("C"));
        TotalPay(job3);
    }

    public static void TotalPay(Job method)
    {

        double totalFee = method.Rate * method.Time;
        Console.WriteLine("The total fee is: {0}", totalFee.ToString("C"));
    }
}

class Job
{

    public Job(string description, double time, double rate)
    {
        Description = description;

        Time = time;

        Rate = rate;
    }

    public static Job operator +(Job first, Job second)
    {
        string newDescription = first.Description + " and " + second.Description;

        double newTime = first.Time + second.Time;

        double newRate = (first.Rate + second.Rate) / 2;

        double newTotalFee = newRate * newTime;

        return (new Job(newDescription, newTime, newRate));
    }

    public string Description { get; set; }
    public double Time { get; set; }
    public double Rate { get; set; }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!