gpt4 book ai didi

c# - 获取不一致的可访问性错误

转载 作者:行者123 更新时间:2023-11-30 19:17:36 26 4
gpt4 key购买 nike

我遇到了一点问题,我似乎无法解决,有人可以帮助我吗,
这些是错误:

Error 1 Inconsistent accessibility: field type 'Flashloader.Toepassing' is less accessible than field 'Flashloader.NewApplication.Toepassing'

Error 2 Inconsistent accessibility: parameter type 'Flashloader.toepassinginifile' is less accessible than method 'Flashloader.NewApplication.NewApplication(Flashloader.toepassinginifile)'

所以那些错误但来源在这种情况下非常有用。

来源 1 新应用程序(这是一个 Winform):

namespace Flashloader{

public partial class NewApplication : Form
{
private toepassinginifile _toepassinginifile;

//private controllerinifile _controlIniFile;

public Toepassing toepassing = new Toepassing();

public NewApplication(toepassinginifile iniFile)
{
_toepassinginifile = iniFile;

InitializeComponent();
}

private void button4_Click(object sender, EventArgs e)
{
this.Close();
}

private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Srec Files (.a20; .a21; .a26; .a44)|*.a20; *.a21; *.a26; *.a44|All files (*.*)|*.*";

openFileDialog1.Title = ("Choose a file");
openFileDialog1.InitialDirectory = Path.Combine(Directory.GetCurrentDirectory());
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
fileBox.Text = (System.IO.Path.GetFileName(openFileDialog1.FileName));
}
}

private void button3_Click(object sender, EventArgs e)
{
toepassing.Name = nameBox.Text;
toepassing.Controller = controllerComboBox.SelectedItem;
toepassing.TabTip = descBox.Text;
toepassing.Lastfile = openFileDialog1.FileName;
fileBox.Text = openFileDialog1.FileName;


if (nameBox.Text == "")
MessageBox.Show("You haven't assigned a Name");
else if (controllerComboBox.Text == "")
MessageBox.Show("You haven't assigned a Controller");
else if (descBox.Text == "")
MessageBox.Show("You haven't assigned a Desciption");
else if (fileBox.Text == "")
MessageBox.Show("You haven't assigned a Applicationfile");
_toepassinginifile.ToePassingen.Add(toepassing);
_toepassinginifile.Save();

MessageBox.Show("Save Succesfull");



this.Close();
}

}}

来源 2 flashloader.toepassing 文件(这是一个类):

namespace Flashloader{
class Toepassing
{
private String _name;

public String Name
{
get { return _name; }
set { _name = value; }
}

public Controller Controller = null;
public String TabTip = "";
public String Lastfile = "";

[Obsolete]
public String Baudrate = "";

[Obsolete]
public String Port = "";

public String Useboot = "";

public Toepassing()
{
Name = "";
}

public Toepassing(String naam)
{
Name = naam;
}

public override String ToString()
{
return Name + " :" + TabTip;
}
}
}

最后源代码 3 flashloader.toepassinginifile(另一个类):

namespace Flashloader
{
class toepassinginifile
{
private const String FILE_NAME = "flash.ini";
private Controllerlist _controllers;
public Toepassinglist ToePassingen { get; private set; }
public Settings Settings { get; private set; }


public toepassinginifile( Controllerlist controllers)
{
_controllers = controllers;

// TODO Startup class maken en laden
ToePassingen = LoadToepassingen();
}

private Toepassinglist LoadToepassingen()
{
StringList input = new StringList().FromFile( FILE_NAME );
Toepassinglist output = new Toepassinglist();

Settings settings = null;
Toepassing toepassing = null;

foreach (var item in input)
{
String line = item.Trim();

if (line.StartsWith("[") && line.EndsWith("]"))
{
settings = null;
toepassing = null;

String name = line.Substring(1, line.Length - 2);

if (name.ToUpper().Equals("STARTUP"))
{
Settings = settings = new Settings();
continue;
}
// TODO kan weg in de toekomst
if ( name.ToUpper().Equals("DRAG && DROP"))
{
toepassing = null;
continue;
} // */

toepassing = new Toepassing(name);
output.Add(toepassing);
}
else if (settings != null)
{
int index = line.IndexOf('=');
if (index < 0)
continue;

String key = line.Substring(0, index).Trim();
String value = line.Substring(index + 1).Trim();

if (Utils.EqualsIgnoreCase(key, "Baudrate"))
Settings.Baudrate = value;
else if (Utils.EqualsIgnoreCase(key, "Port"))
Settings.Port = value;
}
else if (toepassing != null)
{
int index = line.IndexOf('=');
if (index < 0)
continue;

String key = line.Substring(0, index).Trim();
String value = line.Substring(index + 1).Trim();

if (Utils.EqualsIgnoreCase(key, "TabTip"))
toepassing.TabTip = value;
else if (Utils.EqualsIgnoreCase(key, "Controller"))
toepassing.Controller = _controllers.FindByName(value);
else if (Utils.EqualsIgnoreCase(key, "Lastfile"))
toepassing.Lastfile = value;
else if (Utils.EqualsIgnoreCase(key, "Useboot"))
toepassing.Useboot = value;
}
}
return output;
}

public void Save()
{
StringList list = new StringList();

Toepassing settings = new Toepassing("[Startup]");

list.Add("["+settings.Name+"]");
list.Add("LastUsed=");
list.Add("Port=" +settings.Port);
list.Add("Baudrate=" +settings.Baudrate);

foreach (Toepassing item in ToePassingen)
{
list.Add( "[" + item.Name + "]" );
list.Add( "Controller=" + item.Controller.Name );
list.Add( "TabTip="+ item.TabTip );
list.Add("LastFile="+ item.Lastfile);
list.Add("UseBoot="+ item.Useboot);
}

Toepassing dragndrop = new Toepassing("[Drag && Drop]");

list.Add("["+dragndrop.Name+"]");
list.Add("Autostart=");
list.Add("Baudrate="+ dragndrop.Baudrate);
list.Add("Port="+ dragndrop.Port);
list.Add("Lasfile="+ dragndrop.Lastfile);

list.ToFile(FILE_NAME);
}
}
}

如果我能得到一些帮助,解决错误会容易得多。

修复了

最佳答案

由于 toepassinginifile 用于 public 类型的 public 方法,它本身必须由 public (它目前是内部的)。变化:

class toepassinginifile

到:

public class toepassinginifile

甚至更好;p

public class ToePassingIniFile

对于另一个,由于 Toepassing 被用作 public 类型的 public 字段,Toepassing 本身必须是 public

最后的想法:public 字段很少是个好主意; public property 会更好:

private Toepassing toepassing = new Toepassing();
public Toepassing Toepassing {get { return toepassing; } }

关于c# - 获取不一致的可访问性错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17229316/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com