Solved

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

Posted on 2006-07-11
6
2,065 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 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

16 Experts available now in Live!

Get 1:1 Help Now