constructor overloading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rude Dog

    #1

    constructor overloading

    The question below was probably asked, but I couldn't find
    it.

    If you have a class with an overloaded constructor, how do
    you have one constructor call another? In Java the this
    operator does the trick. What about C# ?
  • Jon Skeet

    #2
    Re: constructor overloading

    Rude Dog <jonathanm@usa. com> wrote:[color=blue]
    > The question below was probably asked, but I couldn't find
    > it.
    >
    > If you have a class with an overloaded constructor, how do
    > you have one constructor call another? In Java the this
    > operator does the trick. What about C# ?[/color]

    eg

    public Foo(int x)
    {
    }

    public Foo() : this (5)
    {
    }

    See http://www.pobox.com/~skeet/csharp/constructors.html

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...