Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Static member cannot be accessed with an instance reference; qualify it with a type name instead

Posted on 2006-07-11
6
2,069 Views
Last Modified: 2008-01-09
Hi,

I've got this error: Static member 'System.Text.RegularExpressions.Regex.IsMatch(string, string)' cannot be accessed with an instance reference; qualify it with a type name instead

I really can't find what's going wrong. Another solution on EE gives an answer: use classname, but that's what I do. (const.InvalidAlbumPattern). Still the error occurs...


below a code snippet:
public sealed class FileManager
    {
        private class Consts
        { ...
                        public const string InvalidAlbumPattern = "[\\\\/:*?\"<>|]";
          ...
        }

        public static bool IsValidAlbumName(string name)
        {
            Regex reg;
            if (reg.IsMatch(name, Consts.InvalidAlbumPattern)) <<<<<--------- HERE'S THE ERROR
            {
                return false;
             }
         ...
         }
     }

Thanks in advance
kGenius
0
Comment
Question by:kGenius
6 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 17083565
if (Regex.IsMatch(name, Consts.InvalidAlbumPattern))
0
 
LVL 9

Expert Comment

by:DrAske
ID: 17083795
>> use classname, but that's what I do.
The Error occured because of *IsMatch* method NOT *Consts.InvalidAlbumPattern* ..
So As *AlexFM* posted .. Use The class name *Regex* (where the *IsMethod* method is implemented ..)
WHY TO DO THAT ??
Because It Is A Static Member(Method) ..

regards, Ahmad;
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17083852
What is the point to post duplicated answer?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 9

Expert Comment

by:DrAske
ID: 17083929
>>use classname, but that's what I do.<<
It Is Not A Duplicated Answer .. I've just provided my post with some explanation about the error ..
As He Mentioned , He thought the problem because *InvalidAlbumPattern* ..

Sorry If I made you upset ..

* kGenius * please don't consider my post as an answer ..

thanx, Ahmad;
0
 
LVL 11

Expert Comment

by:vo1d
ID: 17085027
there is nothig bad in giving some more explanations alex. ;)
regards
0
 
LVL 7

Author Comment

by:kGenius
ID: 17088101
Well DrAske thanks for the explanation. But I've found the solution 5 minutes after posting the question... I've searched for this for hours. Then I get this genius idea (hmm) to change the InvalidAlbumPattern to a hard coded string("...").
And still error occurs. Then my light burned ! It must gave been the reg.IsMatch -> RegEx.IsMatch.
Nevertheless AlexFM and DrAske both thanks for the help.
And AlexFM gets the points as he came up with the answer...
DrAske you're too good, giving explanation without waiting for points. That's what the world makes so good, AlexFM. Helping eachother without waiting for a reward !

kGenius
genius is 1% inspiration and 99% perspiration
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question