can a construct call another construct? 
Author Message
 can a construct call another construct?

Seems to me tht in C# you can let one construct call another construct:

public class Foo {
    public Foo() {
        //do something;
    }

    public Foo(int ID)  {
        //do something with ID;
        Foo();
    }

Quote:
}

This really limits the flexibility of initializing varisous parameters in
the constructors.  Did I miss anything?


Sun, 04 Jul 2004 01:48:17 GMT  
 can a construct call another construct?
Bob,

    You can call another construct, like so:

public Foo(int ID) : this()
{

Quote:
}

    Hope this helps.

--
                              - Nicholas Paldino [.NET MVP]


Quote:
> Seems to me tht in C# you can let one construct call another construct:

> public class Foo {
>     public Foo() {
>         //do something;
>     }

>     public Foo(int ID)  {
>         //do something with ID;
>         Foo();
>     }
> }

> This really limits the flexibility of initializing varisous parameters in
> the constructors.  Did I miss anything?



Sun, 04 Jul 2004 02:51:06 GMT  
 can a construct call another construct?

Quote:

> Seems to me tht in C# you can let one construct call another construct:

> public class Foo {
>     public Foo() {
>         //do something;
>     }

>     public Foo(int ID)  {
>         //do something with ID;
>         Foo();
>     }
> }

> This really limits the flexibility of initializing varisous parameters in
> the constructors.  Did I miss anything?

The second constructor above, public Foo(int ID), won't compile -- the line
"Foo();" will cause an error.  You can't call another constructor directly.
You can, however, actually create another instance in a constructor, e.g.,

    public Foo(int ID) {
        Foo f = new Foo();
    }

--
For mail, please use my surname where indicated:



Sun, 04 Jul 2004 02:52:14 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Constructing a function call ?

2. Final Construct gettin called multiple times

3. Constructing a member out of the class constructor

4. Constructing a class in a static library

5. XSD-generated C# classes using the choice construct

6. Another construct using GOTO

7. construct a char from two ints?

8. Is recursion a looping construct?

9. New c99 constructs - details?

10. Unsure about this construct

11. unfamiliar C construct

12. Why are compilers free to ignore certain constructs?

 

 
Powered by phpBB® Forum Software