1
Reply

error when I declare it as a "public".

k

k

Oct 21 2008 2:13 AM
4.1k
I try to to serialize Dictionary object to xml file. That why I have to declare like this public Dictionary dict for object dict.

But If I declare "public" for object dict there was a error occur: error CS0052: Inconsistent accessibility: field type 'HashTableDictionary.Dictionary' is less accessible than field 'HashTableDictionary.Form1.dict'

It I declare "private" for object dict. It's was ok, but my serialize function do not work.

Anyone can help me to solve error CS0052 and explain it for me?? thanks in advance!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HashTableDictionary
{
    class Node
    {
        public string word;
        public string mean;
        public Node next;
        ...
    }
   class LinkList : Node
    {
        public Node[] hashtable = new Node[26];
        ...
    }
   class Dictionary : LinkList
    {
        public Dictionary() { }
        ...
    }
}

//in another file:
namespace HashTableDictionary
{
    public partial class Form1 : Form
    {
        public string[] buffer = new string[200];
        public int i;
        public Dictionary dict = new Dictionary();  //error here!
        ...
    }
    private void Save_btn_Click(object sender, EventArgs e)
    {
            XmlSerializer s = new XmlSerializer(typeof(Dictionary));
            TextWriter tr = new StreamWriter("DictXml.xml");
            s.Serialize(tr,dict);
            tr.Close();
    }
}

Answers (1)