Results 1 to 5 of 5

Thread: [Resolved] Overriding...

  1. #1

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    [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

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    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

  3. #3

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  4. #4
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    This may help you.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  5. #5

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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
  •  



Click Here to Expand Forum to Full Width