static

  • Thread starter Thread starter nicol
  • Start date Start date
N

nicol

Hi all
I think I can not understand the exact usage of static


using System;
namespace ConsoleApplication119
{
class Program
{
static void Main(string[] args)
{
// student p =new student ();
}
}
static class student
{
public static student() // error+++++

{
Console.WriteLine(" parent class");
}
}
static class me : student // error****************
{

}
}
Error 1 Static classes must derive from object.
Error 2 access modifiers are not allowed on static constructors
Thanks . . .
 
I think I can not understand the exact usage of static

using System;
namespace ConsoleApplication119
{
class Program
{
static void Main(string[] args)
{
// student p =new student ();
}
}
static class student
{
public static student() // error+++++

{
Console.WriteLine(" parent class");
}
}
static class me : student // error****************
{

}
}
Error 1 Static classes must derive from object.
Error 2 access modifiers are not allowed on static constructors

The error texts seems clear to me.

And makes sense.

Since a static constructor is not called from any code, then
access modifiers does not make sense.

Since a static class can only contain static methods, then
inheriting from another class does not make much much sense
either.

Arne
 
nicol said:
Hi all
I think I can not understand the exact usage of static


using System;
namespace ConsoleApplication119
{
class Program
{
static void Main(string[] args)
{
// student p =new student ();
}
}
static class student
{
public static student() // error+++++

{
Console.WriteLine(" parent class");
}
}
static class me : student // error****************
{

}
}
Error 1 Static classes must derive from object.
Error 2 access modifiers are not allowed on static constructors
Thanks . . .

You should not make the "student" and "me" classes static, as you want
to create instances of them.

The constructor should not be static either. A class can have a static
constructor, but that's not used for creating instances but to
initialise static members.
 
Back
Top