错误CS0051(可访问性不一致:参数类型'工作'大于法“AddJobs.TotalPay(工作)”少访问) [英] Error CS0051 (Inconsistent accessibility: parameter type 'Job' is less accessible than method 'AddJobs.TotalPay(Job)')

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

问题描述

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



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




设计作业类哈罗德的家庭服务。类包含四个数据字段在职
描述(例如,洗窗),时间以小时来完成作业(为
例如,3.5),每-Hour率收取作业(例如,$ 25.00),和
作业(时薪倍小时)的总费用。包含属性来获取和设置每个字段除
的总费用 - 即场将只读的,其价值计算,每次无论是
每小时收费或小时设置的号码。
重载+运算符,这样两个作业
可以是加入两个作业的总和是含有
原来工作的描述中,新的作业(通过加入和),时间以小时为原始作业的总和,和
中的平均的时薪为原来的作业。编写演示了所有方法正常工作一个main()函数。将文件另存为DemoJobs.cs。



微软的Visual C#®2008年,介绍了面向对象编程,3E,乔伊斯·法雷尔




下面是源代码:

 使用系统; 

酒店的公共类AddJobs
{
私人双totalFee;

公共AddJobs(双totalFee)
{
TotalFee = totalFee;
}

公共静态无效的主要()
{
工作JOB1 =新的工作(洗窗,5.00,25.00);
工作JOB2 =新的工作(遛狗,3.00,11.00);
工作JOB3;
JOB3 = JOB1 JOB2 +;

Console.WriteLine(第一份工作的描述: {0}完成作业所需时间\\\
Total:{1}小时\\\
Hourly费用:{2}每小时,job1.Description,job1.Time,job1.Rate.ToString(C));
TotalPay(JOB1);

Console.WriteLine(第二职业的描述:{0}完成作业所需时间\\\
Total:{1}小时\\\
Hourly费:{2 }每小时,job2.Description,job2.Time,job2.Rate.ToString(C));
TotalPay(JOB2);

Console.WriteLine(第三作业的描述:{1}小时\\\
Hourly费:{2}每小时{0}完成工作所需的时间\\\
Total,job3.Description ,job3.Time,job3.Rate.ToString(C));
TotalPay(JOB3);
}

公共静态无效TotalPay(作业方法)
{

双totalFee = Job.rate * Job.time;
Console.WriteLine(总费用为:{0},TotalFee.ToString(C));
}
}

类招聘
{

公开招聘(字符串描述,双倍时间,双倍速率)
{
说明=描述;

的时间=;

率=率;
}

公共静态招聘运营商+(工作第一,第二作业)
{
串newDescription = first.Description +和+ second.Description;

双NEWTIME = first.Time + second.Time;

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

双newTotalFee = newRate * NEWTIME;

返回(新工作(newDescription,NEWTIME,newRate));
}

公共字符串描述{搞定;设置;}
公共双倍{搞定;设置;}
公共双倍速率{搞定;设置;}
}


解决方案

您避风港' :T指定类,这使得它的内部能见度修改



尝试改变这一行:

 类招聘

这样:

 公共类招聘


I compiled and ran the source code below successfully by omitting the totalFee field. How do I write totalFee into this program so that it will accurately calculate the total fee for each job (rate * time)? Below, you'll see I tried using a method; which generated the error CS0051 (Inconsistent accessibility: parameter type 'Job' is less accessible than method 'AddJobs.TotalPay(Job)').

This source code is in response to the following assignment:

"Design a Job class for Harold’s Home Services. The class contains four data fields—Job description (for example, "wash windows"), time in hours to complete the Job (for example, 3.5), per-hour rate charged for the Job (for example, $25.00), and total fee for the Job (hourly rate times hours). Include properties to get and set each field except the total fee—that field will be read-only, and its value is calculated each time either the hourly fee or the number of hours is set. Overload the + operator so that two Jobs can be added. The sum of two Jobs is a new Job containing the descriptions of both original Jobs ( joined by "and"), the sum of the time in hours for the original Jobs, and the average of the hourly rate for the original Jobs. Write a Main()function that demonstrates all the methods work correctly. Save the file as DemoJobs.cs."

Microsoft® Visual C#® 2008, An Introduction to Object-Oriented Programming, 3e, Joyce Farrell

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(工作)”少访问)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆