Tristan <(E-Mail Removed)> wrote:
> I am trying to call an overloaded constructor from within an another
> one with parameters that have to be processed inside the constructor.
> Therfore I can't use the Constructor() : Constructor(params) type of
> syntax. I think the code below, explains better what I'm trying to do.
>
> Class AClass
> {
> AClass(string fileName)
> { }
>
> AClass(string key)
> {
> // Do some special processing on key to get a fileName
>
> // Here I want to call AClass(fileName) but how!!!!
> }
> }
>
> I suspect this isn't possible and I just have to define some private
> method that can get called by both constructors?
Well, the first problem is that both of those constructors have the
same signature. However, once you've got rid of that, the way to
proceed is:
AClass (string key) : this (KeyToFilename(key))
{
}
// FileInfo used here as example
static FileInfo KeyToFilename(string key)
{
....
}
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too