可访问性不一致如何解决不一致的可访问性C#问题 [英] Inconsistent accessibility how do I solve inconsistent accessibility C# problem

查看:573
本文介绍了可访问性不一致如何解决不一致的可访问性C#问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我尝试运行程序时都会收到此错误



错误CS0053可访问性不一致:属性类型实习生的可访问性低于属性frm3Update.TraineeUpdate



请帮助



我尝试了什么:



来自第二张表单的按钮

Each time i try to run programme i get this error

Error CS0053 Inconsistent accessibility: property type 'Trainee' is less accessible than property 'frm3Update.TraineeUpdate'

please help

What I have tried:

Button from second form

private void BtnUpdate_Click(object sender, EventArgs e)
{
	if (Candidate.Count == 0)
	{
		MessageBox.Show("There is nothing to update.");
	}
	else
	{
		FrmUpdate my = new FrmUpdate();
		icnt1 = DGTrainee.CurrentCell.RowIndex;
		my.TraineeUpdate = Candidate[icnt1];
		my.ShowDialog();
		Candidate[icnt1] = my.TraineeUpdate;
	}
} 


public partial class frm3Update : Form
{
	public frm3Update()
	{
		InitializeComponent();
	}

	private Trainee mUpdateTrainee;
	public Trainee TraineeUpdate
	{
		get { return mUpdateTrainee; }
		set { mUpdateTrainee = value; }
	}


	private void frm3Update_Load(object sender, EventArgs e)
	{
		txtName.Text = TraineeUpdate.Name;
		txtSurname.Text = TraineeUpdate.Surname;
		nudAge.Value = TraineeUpdate.Age;
		txtTrainingExp.Text = TraineeUpdate.Experience;
		txtGender.Text = TraineeUpdate.Gender;
	}

	private void btnUpdateTrainee_Click(object sender, EventArgs e)
	{
		TraineeUpdate.Name = txtName.Text;
		TraineeUpdate.Surname = txtSurname.Text;
		TraineeUpdate.Gender = txtGender.Text;
		TraineeUpdate.Age = Convert.ToInt32(nudAge.Value);
		TraineeUpdate.Experience = txtTrainingExp.Text;
		this.Close();
	}
}

推荐答案

代码无法运行,因为编译器错误很明显并且阻止了代码来自编译。



这是关于编译器错误CS0053(C#) [ ^ ]

The code does not run as the compiler error is pretty clear and preventing the code from compiling.

Here is the official documentation on the Compiler Error CS0053 (C#)[^]
Quote:

公共构造必须返回可公开访问的对象。有关详细信息,请参阅访问修饰符(C#编程指南) [ ^ ] 。

A public construct must return a publicly accessible object. For more information, see Access Modifiers (C# Programming Guide)[^].



所以,物业类型'实习生'比财产'frm3Update.TraineeUpdate'更难以获取,这就是说这是你的问题:


So, "property type 'Trainee' is less accessible than property 'frm3Update.TraineeUpdate'" is say that this is your problem:

private Trainee mUpdateTrainee;
public Trainee TraineeUpdate
{
    get { return mUpdateTrainee; }
    set { mUpdateTrainee = value; }
}



Traniee 类(未提供)未标有 public accessor。


The Traniee class (not provided) is not marked with a public accessor.


这篇关于可访问性不一致如何解决不一致的可访问性C#问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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