S
Siegfried Heintze
(1) Can someone help me make the program below work? Line 26 throws an
exception. Something about property not supported?
(2) I tried writing cons["a"]["b"] = "hello" and this did not work because
cons["a"] was not initalized. How can I implement the descendant class SD so
it will automatically initialize new entries in the table to mimic the C++
class std::map<K,V> where I can write cons["a"]["b"]="hello"?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; /* 5*/
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;
namespace DeleteMe_Test004_2D_HashTables
{ /* 10*/
class SD<K,V> : System.Collections.Generic.SortedDictionary<K,V>
{ }
public class Program {
static System.IO.TextWriter outp = System.Console.Out;
public static void Main(string[] args){/* 15*/
try{
SD<string, SD<string, string>> cons
=new SD<string,SD<string,string>>();
cons.Add("a",new SD<string,string>());
cons["a"].Add("b", "hello"); /* 20*/
foreach (string src in cons.Keys)
foreach (string dst in cons[src].Keys)
outp.WriteLine("cons[" + src + "]"
+ "[" + dst + "]=" + cons[src][dst]);
/* 25*/
XmlSerializer sr = new XmlSerializer(
typeof(SD<string, SD<string, string>>));
sr.Serialize(outp, cons);
} finally {
} /* 30*/
}
}
}
exception. Something about property not supported?
(2) I tried writing cons["a"]["b"] = "hello" and this did not work because
cons["a"] was not initalized. How can I implement the descendant class SD so
it will automatically initialize new entries in the table to mimic the C++
class std::map<K,V> where I can write cons["a"]["b"]="hello"?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO; /* 5*/
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;
namespace DeleteMe_Test004_2D_HashTables
{ /* 10*/
class SD<K,V> : System.Collections.Generic.SortedDictionary<K,V>
{ }
public class Program {
static System.IO.TextWriter outp = System.Console.Out;
public static void Main(string[] args){/* 15*/
try{
SD<string, SD<string, string>> cons
=new SD<string,SD<string,string>>();
cons.Add("a",new SD<string,string>());
cons["a"].Add("b", "hello"); /* 20*/
foreach (string src in cons.Keys)
foreach (string dst in cons[src].Keys)
outp.WriteLine("cons[" + src + "]"
+ "[" + dst + "]=" + cons[src][dst]);
/* 25*/
XmlSerializer sr = new XmlSerializer(
typeof(SD<string, SD<string, string>>));
sr.Serialize(outp, cons);
} finally {
} /* 30*/
}
}
}