I am puzzled by static class use

I

intrader

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
 
B

Bruce Wood

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

intrader

Bruce said:
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
 
B

Bruce Wood

Bruce said:
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.
 
I

intrader

Bruce said:
Bruce said:
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
 
I

intrader

Bruce said:
Bruce said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top