Solved

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

Posted on 2006-07-11
6
2,063 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now