[Mono-dev] Re: Constructor implementation obligation via interface?

Kamil Skalski kamil.skalski at gmail.com
Wed May 24 10:32:41 EDT 2006


Of course strictly speaking you cannot create class WITHOUT ANY
constructor. If you don't specify any, the default empty ctor is
generated by compiler.
You can create a class without an empty ctor though, by defining the
one with some parameters.

I guess the only way to statically enforce having the empty ctor in a
class is by hack provided by Jb.

2006/5/24, Ympostor <ympostor at clix.pt>:
> Kamil Skalski escribió:
> > There is a slight problem. In C# empty constructors are added
> > automatically, so you can't define a class without empty constructor.
> > What you can do is to define a class with private empty constructor,
> > which will prevent user from instanciating it directly. I guess there
> > is not way to forbid this.
>
> Thanks for your comment.
>
> But sorry because I think I haven't understood you completely.
>
> You say I can't define a class without empty constructor? That's not
> true. When you create an empty Console application in Visual Studio,
> there is a "class Program" that contains an static method but does not
> have any constructor.
>
> If you were trying to say that all classes, at the compiler level,
> contain an empty constructor, then ok; but what I want to do is to force
> a class to have a public empty constructor, and, if it doesn't have it,
> have the compiler to warn me because of the semantic requisite.
>
> Is there a way to achieve this?
>
> Regards.
>
> --
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>


-- 
Kamil Skalski
http://nazgul.omega.pl


More information about the Mono-devel-list mailing list