|
-
Jul 8th, 2003, 10:14 PM
#1
Thread Starter
Frenzied Member
Class won't compile
When I try to compile my class, I keep getting this error.
error CS0246: The type or namespace name 'Dictionary' could not be found (are your missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'dict' could not be found (are you missing a using directive or an assembly reference?)
I am writing the code in notepad and compiling with the command line.
here's my code
Code:
using System;
using System.Collections;
class CH1_12 {
public static void Main()
{
Dictionary dict = new Dictionary();
dict.Add(1, "C++");
dict.Add(2, "C");
dict.Add(3, "Ada");
dict.Add(4, "APL");
dict.Add(5, "VB");
dict.Add(6, "C#");
dict.Add(7, "Java");
dict.Add(8, "FORTRAN");
//Print out the list
Console.WriteLine("Before Deleting Anything");
foreach(DictionaryEntry de in dict)
{
Console.WriteLine("Entry Key {0} Value {1}", de.Key, de.Value);
}
dict.Remove(4);
dict.Remove(7);
Console.WriteLine("After Deletions");
foreach(DictionaryEntry de in dict)
{
Console.WriteLine("Entry Key {0} Value {1}", de.Key, de.Value);
}
}
}
and ideas on what's going on?????
Last edited by Memnoch1207; Jul 8th, 2003 at 10:56 PM.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jul 8th, 2003, 11:22 PM
#2
Frenzied Member
There is no Dictionary class. There is only a DictionaryBase, and its an abstract class.
-
Jul 9th, 2003, 12:13 AM
#3
Thread Starter
Frenzied Member
Blame it on the old ass book!
just ran into another problem with the book with converting data types
this works
Code:
string s1 = "123.45"
single sngl1 = Convert.ToSingle(s1);
int i1 = Convert.ToInt16(sngl1);
but the books way doesn't work
Code:
string s1 = "123.45"
single sngl1 = s1.ToSingle();
int i1 = sngl1.ToInt16();
BTW, how to I get the above Dictionary code to work???
DictionaryBase doesn't have Add, Remove or Insert Methods... but IDictionary has .Add and .Remove methods.
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jul 9th, 2003, 12:36 AM
#4
Frenzied Member
You can use a Hastable or a SortedList. IDictionary is the interface you would have to inherit if you want to implement its methods in your own custom class, so it cant be instantiated.
-
Jul 9th, 2003, 12:40 AM
#5
Thread Starter
Frenzied Member
good, I am familiar with the hashtable... thanks for the help devgrp!
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|