By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,775 Members | 1,347 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,775 IT Pros & Developers. It's quick & easy.

I am puzzled by static class use

P: n/a
The code is:
<code>
namespace ConsoleApp
{
public interface Ivalidator{
String ErrorMessage{get;}
Boolean IsValid{get;}
void Validate(string value,long mask,
long maxLength,string dispName,string sExtra);
}
public class Validator:IValidator{
private String _errorMessage="";
private Boolean _isValid=false;
public String ErrorMessage{get{return _errorMessage;}}
public Boolean IsValid{get{return _isValid;}}
public void Validate(string value,long mask,
long maxLength,string dispName,string sExtra)
}

static class CValidator:ValidatorBase{}

///This gives me an error at this point stating "A namespace does not
///directly contain members such as fields or method"

class ValidatorBaseTest{
static void Main(string[] args){}
}
}
</code>
Here I trying to build a static class that provide validation for an
incoming value and metadata provided in the Validate call.

The message puzzles me "... does not..." implies that what the problem
is that I don't have any fields or methods directly in the namespace; if
I supply them, I get yet more errors, so that is not the problem.

I can write
<code>
class CValidator:ValidatorBase{
public static void Validate((string value,long mask,
long maxLength,string dispName,string sExtra){}
}
</code>
Is it not the same thing?

Why the error when I use 'static class ...'

Thanks
Jan 27 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a


On Jan 26, 4:17 pm, intrader <intra...@aol.comwrote:
The code is:
<code>
namespace ConsoleApp
{
public interface Ivalidator{
String ErrorMessage{get;}
Boolean IsValid{get;}
void Validate(string value,long mask,
long maxLength,string dispName,string sExtra);
}
public class Validator:IValidator{
private String _errorMessage="";
private Boolean _isValid=false;
public String ErrorMessage{get{return _errorMessage;}}
public Boolean IsValid{get{return _isValid;}}
public void Validate(string value,long mask,
long maxLength,string dispName,string sExtra)
}

static class CValidator:ValidatorBase{}

///This gives me an error at this point stating "A namespace does not
///directly contain members such as fields or method"

class ValidatorBaseTest{
static void Main(string[] args){}
}}</code>
Here I trying to build a static class that provide validation for an
incoming value and metadata provided in the Validate call.

The message puzzles me "... does not..." implies that what the problem
is that I don't have any fields or methods directly in the namespace; if
I supply them, I get yet more errors, so that is not the problem.

I can write
<code>
class CValidator:ValidatorBase{
public static void Validate((string value,long mask,
long maxLength,string dispName,string sExtra){}}</code>
Is it not the same thing?

Why the error when I use 'static class ...'
What version of Visual Studio are you running? static classes were
introduced in .NET 2.0 and work only in Visual Studio 2005.

Jan 27 '07 #2

P: n/a
Bruce Wood wrote:
>
On Jan 26, 4:17 pm, intrader <intra...@aol.comwrote:
>The code is:
<code>
namespace ConsoleApp
{
public interface Ivalidator{
String ErrorMessage{get;}
Boolean IsValid{get;}
void Validate(string value,long mask,
long maxLength,string dispName,string sExtra);
}
public class Validator:IValidator{
private String _errorMessage="";
private Boolean _isValid=false;
public String ErrorMessage{get{return _errorMessage;}}
public Boolean IsValid{get{return _isValid;}}
public void Validate(string value,long mask,
long maxLength,string dispName,string sExtra)
}

static class CValidator:ValidatorBase{}

///This gives me an error at this point stating "A namespace does not
///directly contain members such as fields or method"

class ValidatorBaseTest{
static void Main(string[] args){}
}}</code>
Here I trying to build a static class that provide validation for an
incoming value and metadata provided in the Validate call.

The message puzzles me "... does not..." implies that what the problem
is that I don't have any fields or methods directly in the namespace; if
I supply them, I get yet more errors, so that is not the problem.

I can write
<code>
class CValidator:ValidatorBase{
public static void Validate((string value,long mask,
long maxLength,string dispName,string sExtra){}}</code>
Is it not the same thing?

Why the error when I use 'static class ...'

What version of Visual Studio are you running? static classes were
introduced in .NET 2.0 and work only in Visual Studio 2005.
I was not aware of this. I am using Visual Studio 2003.

I also have Visual Studio 2005, and I will try that.
Thanks
Jan 27 '07 #3

P: n/a


On Jan 26, 4:42 pm, intrader <intra...@aol.comwrote:
Bruce Wood wrote:
On Jan 26, 4:17 pm, intrader <intra...@aol.comwrote:
The code is:
<code>
namespace ConsoleApp
{
public interface Ivalidator{
String ErrorMessage{get;}
Boolean IsValid{get;}
void Validate(string value,long mask,
long maxLength,string dispName,string sExtra);
}
public class Validator:IValidator{
private String _errorMessage="";
private Boolean _isValid=false;
public String ErrorMessage{get{return _errorMessage;}}
public Boolean IsValid{get{return _isValid;}}
public void Validate(string value,long mask,
long maxLength,string dispName,string sExtra)
}
static class CValidator:ValidatorBase{}
///This gives me an error at this point stating "A namespace does not
///directly contain members such as fields or method"
class ValidatorBaseTest{
static void Main(string[] args){}
}}</code>
Here I trying to build a static class that provide validation for an
incoming value and metadata provided in the Validate call.
The message puzzles me "... does not..." implies that what the problem
is that I don't have any fields or methods directly in the namespace; if
I supply them, I get yet more errors, so that is not the problem.
I can write
<code>
class CValidator:ValidatorBase{
public static void Validate((string value,long mask,
long maxLength,string dispName,string sExtra){}}</code>
Is it not the same thing?
Why the error when I use 'static class ...'
What version of Visual Studio are you running? static classes were
introduced in .NET 2.0 and work only in Visual Studio 2005.I was not aware of this. I am using Visual Studio 2003.

I also have Visual Studio 2005, and I will try that.
Thanks
In VS2003, you don't declare it "static": you just given it a private
constructor and make every method static. You get the same effect; it's
just that the compiler doesn't enforce it for you.

Jan 27 '07 #4

P: n/a
Bruce Wood wrote:
>
On Jan 26, 4:42 pm, intrader <intra...@aol.comwrote:
>Bruce Wood wrote:
>>On Jan 26, 4:17 pm, intrader <intra...@aol.comwrote:
The code is:
<code>
namespace ConsoleApp
{
public interface Ivalidator{
String ErrorMessage{get;}
Boolean IsValid{get;}
void Validate(string value,long mask,
long maxLength,string dispName,string sExtra);
}
public class Validator:IValidator{
private String _errorMessage="";
private Boolean _isValid=false;
public String ErrorMessage{get{return _errorMessage;}}
public Boolean IsValid{get{return _isValid;}}
public void Validate(string value,long mask,
long maxLength,string dispName,string sExtra)
}
static class CValidator:ValidatorBase{}
///This gives me an error at this point stating "A namespace does not
///directly contain members such as fields or method"
class ValidatorBaseTest{
static void Main(string[] args){}
}}</code>
Here I trying to build a static class that provide validation for an
incoming value and metadata provided in the Validate call.
The message puzzles me "... does not..." implies that what the problem
is that I don't have any fields or methods directly in the namespace; if
I supply them, I get yet more errors, so that is not the problem.
I can write
<code>
class CValidator:ValidatorBase{
public static void Validate((string value,long mask,
long maxLength,string dispName,string sExtra){}}</code>
Is it not the same thing?
Why the error when I use 'static class ...'
What version of Visual Studio are you running? static classes were
introduced in .NET 2.0 and work only in Visual Studio 2005.I was not aware of this. I am using Visual Studio 2003.
I also have Visual Studio 2005, and I will try that.
Thanks

In VS2003, you don't declare it "static": you just given it a private
constructor and make every method static. You get the same effect; it's
just that the compiler doesn't enforce it for you.
Great info, thanks
Jan 27 '07 #5

P: n/a
Bruce Wood wrote:
>
On Jan 26, 4:42 pm, intrader <intra...@aol.comwrote:
>Bruce Wood wrote:
>>On Jan 26, 4:17 pm, intrader <intra...@aol.comwrote:
The code is:
<code>
namespace ConsoleApp
{
public interface Ivalidator{
String ErrorMessage{get;}
Boolean IsValid{get;}
void Validate(string value,long mask,
long maxLength,string dispName,string sExtra);
}
public class Validator:IValidator{
private String _errorMessage="";
private Boolean _isValid=false;
public String ErrorMessage{get{return _errorMessage;}}
public Boolean IsValid{get{return _isValid;}}
public void Validate(string value,long mask,
long maxLength,string dispName,string sExtra)
}
static class CValidator:ValidatorBase{}
///This gives me an error at this point stating "A namespace does not
///directly contain members such as fields or method"
class ValidatorBaseTest{
static void Main(string[] args){}
}}</code>
Here I trying to build a static class that provide validation for an
incoming value and metadata provided in the Validate call.
The message puzzles me "... does not..." implies that what the problem
is that I don't have any fields or methods directly in the namespace; if
I supply them, I get yet more errors, so that is not the problem.
I can write
<code>
class CValidator:ValidatorBase{
public static void Validate((string value,long mask,
long maxLength,string dispName,string sExtra){}}</code>
Is it not the same thing?
Why the error when I use 'static class ...'
What version of Visual Studio are you running? static classes were
introduced in .NET 2.0 and work only in Visual Studio 2005.I was not aware of this. I am using Visual Studio 2003.
I also have Visual Studio 2005, and I will try that.
Thanks

In VS2003, you don't declare it "static": you just given it a private
constructor and make every method static. You get the same effect; it's
just that the compiler doesn't enforce it for you.
Thanks; I have not tried it yet and I understand that you can write a
fully static class with a static constructor with lazy evaluation.
Feb 5 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.