kGenius
asked on
Static member cannot be accessed with an instance reference; qualify it with a type name instead
Hi,
I've got this error: Static member 'System.Text.RegularExpres sions.Rege x.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
I've got this error: Static member 'System.Text.RegularExpres
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
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
{
return false;
}
...
}
}
Thanks in advance
kGenius
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What is the point to post duplicated answer?
>>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;
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;
there is nothig bad in giving some more explanations alex. ;)
regards
regards
ASKER
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
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
The Error occured because of *IsMatch* method NOT *Consts.InvalidAlbumPatter
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;