Class With The Same Name Already Exists

I've created a class named "Group" in my .NET C# web-application.

When I try to access this class within other classes I get into no troubles, however, in certain points within my code when I try to access the very same class, it refers me to a different built-in class named "Group" too under the the lib. Regular Expressions.

My question: How can I specify directly that I am trying to access a different class? If there were 2 classes under different libs. named the same way, I would of just typed X.Group and Y.Group in order to specify the difference, but I'm not sure what I need to type in order to access my manually created class within my code.

EDIT: I have no namespace for my web-application as far as I know. I am using WebForms in order to develop my website, hence no namespace is created as far as I'm concerned.

Thanks in advance.

Jon Skeet
people
quotationmark

How can I specify directly that I am trying to access a different class

You could:

  • Use the fully-qualified name, e.g.

    MyNamespace.Group x = new MyNamespace.Group();
    
  • Avoid adding a using directive for System.Text.RegularExpressions unless you really need it (maybe fully-qualifying uses of that instead)
  • Use an alias via a using directive:

    using MyGroup = MyNamespace.Group;
    ...
    MyGroup x = new MyGroup();
    

If you don't have a namespace declaration, you can just refer to global::Group instead of MyNamespace.Group... but I suspect you do have a namespace, and I'd urge you to create one if you don't already have one.

people

See more on this question at Stackoverflow