S
Siegfried Heintze
This program works except for line 58. I tried to solve the problem by
implementing my own indexer as you can see on line 27.
It says object reference not set to an instance of an object. Use the "new
keyword to create an object instance.
I tried using new but that does not work for built-in or primitive types.
Can anyone help me modify my program so I can create new elements using this
C++ like syntax:
cons["a"]["b"] = "c";
I know I can do it the old manual way and you can see that I have done that
on line 57.
Thanks,
siegfried
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
/* 5*/
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;
/**
/* 10*/
* Begin commands to execute this file using MS.NET with bash
* csc /out
rogram.exe /checked /d:noprompt /debug Program.cs
* ./Program hello there <<EOF
* insert your data here
* EOF
/* 15*/
* rm Program.exe
* rm Program.pdb
* End commands to execute this file using MS.NET with bash
*/
/* 20*/
namespace DeleteMe_Test004_2D_HashTables
{
[XmlRoot("dictionary")]
public class SerializableDictionary<TKey, TValue>
: Dictionary<TKey, TValue>
/* 25*/
{
new public TValue this[TKey index]
{
get
{
/* 30*/
try
{
TValue v = base[index];
return v;
}
/* 35*/
catch (System.Collections.Generic.KeyNotFoundException e)
{
TValue tmp=default(TValue);
base.Add(index, tmp);
return tmp;
/* 40*/
}
}
set
{
base[index] = value;
/* 45*/
}
}
}
public class SD<K, V> : SerializableDictionary<K, V> { }
/* 50*/
public class Program {
static System.IO.TextWriter outp = System.Console.Out;
public static void Main(string[] args){
try{
SD<string, SD<string, string>> cons=new
SD<string,SD<string,string>>();/* 55*/
cons.Add("a",new SD<string,string>());
cons["a"].Add("b", "hello");
cons["qrs"]["tuv"] = "world";
} finally {
}
/* 60*/
}
}
}
implementing my own indexer as you can see on line 27.
It says object reference not set to an instance of an object. Use the "new
keyword to create an object instance.
I tried using new but that does not work for built-in or primitive types.
Can anyone help me modify my program so I can create new elements using this
C++ like syntax:
cons["a"]["b"] = "c";
I know I can do it the old manual way and you can see that I have done that
on line 57.
Thanks,
siegfried
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
/* 5*/
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;
/**
/* 10*/
* Begin commands to execute this file using MS.NET with bash
* csc /out
![Stick Out Tongue :P :P](/styles/default/custom/smilies/tongue.gif)
* ./Program hello there <<EOF
* insert your data here
* EOF
/* 15*/
* rm Program.exe
* rm Program.pdb
* End commands to execute this file using MS.NET with bash
*/
/* 20*/
namespace DeleteMe_Test004_2D_HashTables
{
[XmlRoot("dictionary")]
public class SerializableDictionary<TKey, TValue>
: Dictionary<TKey, TValue>
/* 25*/
{
new public TValue this[TKey index]
{
get
{
/* 30*/
try
{
TValue v = base[index];
return v;
}
/* 35*/
catch (System.Collections.Generic.KeyNotFoundException e)
{
TValue tmp=default(TValue);
base.Add(index, tmp);
return tmp;
/* 40*/
}
}
set
{
base[index] = value;
/* 45*/
}
}
}
public class SD<K, V> : SerializableDictionary<K, V> { }
/* 50*/
public class Program {
static System.IO.TextWriter outp = System.Console.Out;
public static void Main(string[] args){
try{
SD<string, SD<string, string>> cons=new
SD<string,SD<string,string>>();/* 55*/
cons.Add("a",new SD<string,string>());
cons["a"].Add("b", "hello");
cons["qrs"]["tuv"] = "world";
} finally {
}
/* 60*/
}
}
}