|
-
Oct 17th, 2003, 06:29 AM
#1
[Resolved] Overriding...
Let's say I want to inherit Hashtable, and restrict it to allow only strings. I have this...
Code:
public class Class1:Hashtable
{
public Class1() {}
public override void Add(string key, string value)
{
}
}
Which works great in VB (when converted to VB syntax, that is) but in C# I get "no suitable method found to override".
What am I missing?
Last edited by crptcblade; Oct 17th, 2003 at 10:09 AM.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 17th, 2003, 09:06 AM
#2
Frenzied Member
Apparently, it won't let you override the Add() because the signature of the baseclasses Add() takes 2 objects and the method you are trying to use to override it takes 2 strings.
The code below worked for me, but not when the 2 parameters in the Add method were strings.
Code:
using System;
using System.Collections;
public class myClass : Hashtable
{
public override void Add(object key, object value)
{
Console.WriteLine("Key is {0}, value is {1}", key, value);
}
}
class newClass
{
public static void Main()
{
myClass y = new myClass();
y.Add("test", "test2");
}
}
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Oct 17th, 2003, 09:23 AM
#3
Well, the basic goal here is to make a type safe collection. So how would I go about only allowing certain object types, string in this case to be added? And why does this work in VB.NET and not C#?
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 17th, 2003, 09:53 AM
#4
Frenzied Member
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Oct 17th, 2003, 10:09 AM
#5
Originally posted by Memnoch1207
This may help you.
Very much so. Thanks
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
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
|