本文介绍了错误CS0051(可访问性不一致:参数类型'工作'大于法“AddJobs.TotalPay(工作)”少访问)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编译和通过省略totalFee字段下成功运行的源代码。我怎样写totalFee进入这个程序,以便它可以精确计算出总的费用为每个作业(*率时间)?下面,你会看到我尝试使用的方法;它产生的错误CS0051(可访问性不一致:参数类型'工作'大于法AddJobs.TotalPay(工作)少访问)。



这源代码是响应以下分配:



Here is the source code:

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 = Job.rate * Job.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;}
}
解决方案

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

这篇关于错误CS0051(可访问性不一致:参数类型'工作'大于法“AddJobs.TotalPay(工作)”少访问)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 05:49