Why doesn't this throw an exception?

D

Danny Tuppeny

Hi all,

Any ideas why the below code won't throw an exception? It appears that the
base Add method is being called, and not mine :-(

-- Console App --

using System;
using System.Collections.Generic;
using System.Text;

namespace RelationshipListTest
{
class Program
{
static void Main(string[] args)
{
ListTest<int> myList = new ListTest<int>();
myList.Add(1);
}
}

public class ListTest<T> : List<T>
{
new void Add(T item)
{
throw new NotImplementedException();
}
}
}
 
M

Markus Stoeger

Danny said:
Hi all,

Any ideas why the below code won't throw an exception? It appears that the
base Add method is being called, and not mine :-(

Your new Add method is private:
new void Add(T item)

Add the public access modifier, it should throw the exception then.

hth,
Max
 
D

Danny Tuppeny

Markus Stoeger said:
Your new Add method is private:


Add the public access modifier, it should throw the exception then.

LOL!!!

I think I need more coffee!!

Thanks :)
 
D

Danny Tuppeny

Robert Jeppesen durius (dot) com> said:
I felt like a moron too for not seeing it! :)

I guess it's what I get for not learning (Ctrl+C) & implementing (Ctrl+V)
someone elses code!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top