Solved

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

Posted on 2006-07-11
6
2,067 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 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