Well, you can't override a field. But I think you want an indexed property - but you will still need to implement the Add() methods. Take a look here:
https://msdn.microsoft.com/en-us/library/aa288464%28v=vs.71%29.aspx[
^].
[Update1]
If yor only need is to oveddide ToString, override it simply:
public class DB : Dictionary<string,object>
{
public override string ToString()
{
return this.Count.ToString();
}
}
[Update2]
See how real encapsulation and index property could be used in this case. Exactly as you wanted:
public class DB
{
private Dictionary<string,object> DATA = new Dictionary<string,object>();
public DB()
{
this.DATA = new Dictionary<string,object>();
}
public string ToString()
{
return DATA.Count.ToString();
}
public void Add(string index, object value)
{
DATA.Add(index, value);
}
public object this[string index]
{
get
{
if(DATA.ContainsKey(index))
{
return DATA[index];
}
else
{
return null;
}
}
set
{
if(DATA.ContainsKey(index))
{
DATA[index] = value;
}
else
{
DATA.Add(index, value);
}
}
}
}
void Main()
{
DB value = new DB();
value.Add("Attr1", 1);
value.Add("Attr2", 2);
value["Attr1"] = 3;
value["Attr3"] = 4;
Console.WriteLine(value.ToString());
Console.WriteLine(value["Attr1"]);
Console.WriteLine(value["Attr2"]);
Console.WriteLine(value["Attr3"]);
Console.WriteLine(value["Attr4"]);
}