namespace SerializeTest{public partial class Form1 : Form{ public Form1() { InitializeComponent(); } private voID Form1_Load(object sender,EventArgs e) { } private voID serializeConnection(Conn connection) { XmlSerializer serializer = new XmlSerializer(typeof(Conn)); TextWriter textWriter = new StreamWriter(@"serialized.xml"); serializer.Serialize(textWriter,connection); textWriter.Close(); } static List<Conn> deserializeConnection() { XmlSerializer deserializer = new XmlSerializer(typeof(List<Conn>)); TextReader textReader = new StreamReader(@"serialized.xml"); List<Conn> connectionList; connectionList = (List<Conn>)deserializer.Deserialize(textReader); textReader.Close(); return connectionList; } private voID btnSerialize_Click(object sender,EventArgs e) { Conn conn = getConnection(); serializeConnection(conn); } private Conn getConnection() { Conn connection = new Conn(); connection.connectionname = txtname.Text; connection.address = txtAddress.Text; connection.height = 2542; connection.wIDth = 4254; connection.password = txtPassword.Text; connection.smartSizing = false; connection.username = txtUsername.Text; connection.port = 474; return connection; } private voID btnDeserialize_Click(object sender,EventArgs e) { int count = deserializeConnection().Count; lblStatus.Text = "Count: " + count; }}class Conn{ public Conn() { } public string connectionname { get; set; } public int height { get; set; } public int wIDth { get; set; } public string address { get; set; } public string username { get; set; } public string password { get; set; } public int port { get; set; } public bool smartSizing { get; set; }}}
课堂是公开的 – 我不明白可能导致这个错误.任何帮助将不胜感激.
解决方法The Class is public
不,这不对.这是宣言:
class Conn{ ...}
您尚未指定任何访问修饰符,因此默认为内部(假设它是非嵌套的).只是因为它有一个公共构造函数没有公开.您需要明确公开公开:
public class Conn{ ...}总结
以上是内存溢出为你收集整理的c# – 公共课 – “由于其保护等级而无法访问.只能处理公共类型.“全部内容,希望文章能够帮你解决c# – 公共课 – “由于其保护等级而无法访问.只能处理公共类型.“所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)