3

In the class below what does the "owner" argument do to both myClass and the base class?

public class Base
{
    public myClass(owner) : base (owner) { }
}
Arthur Mamou-Mani
  • 2,303
  • 10
  • 43
  • 69
  • 2
    the downvote is very unnecessary! give the op a chance to edit! – Alex Aug 01 '12 at 21:07
  • 3
    It doesn't take the chance away from him, and whoever downvoted can take their -1 back after the question gets rephrased. As of now, I don't even get it. Everyone's guessing what OP meant, which fulfils the definiton of an "unclear or not useful" question – Konrad Morawski Aug 01 '12 at 21:09
  • 1
    It would appear that there is a class called myMethod in your project (or referenced assemblies) and an instance of myMethod is being passed as an argument (named owner) to this 'new' method. Perhaps this (sub)class is named @new ? – Sam Axe Aug 01 '12 at 21:09
  • 2
    @arthurmani what possessed you to use `new` as a sample class name in your question ?! – Alex Aug 01 '12 at 21:21
  • @Xander sorry I got the code through a conversion from VB.net (on developer fusion) and could not recognize the syntax. I understand now thanks to Jason's reply. – Arthur Mamou-Mani Aug 01 '12 at 21:23
  • I (for one) reverted to +1 now ;) – Konrad Morawski Aug 01 '12 at 21:37

2 Answers2

2

If you have two classes, one is a base class the other a derived class, when you create constructor for the derived class, you can pass arguments to the base clas.

public class Base
{
    private string Test = "";

    public Base(string test)
    {
        Test = test;
    }
}

public class Derived : Base
{
    public Derived(string test) : base(test) // - This will call public Base(string test)
    {
    }
}
Jason Evans
  • 28,906
  • 14
  • 90
  • 154
  • 2
    Where is the **`new`** ? `public new (myMethod owner) : base (owner) { }` – L.B Aug 01 '12 at 21:10
  • 1
    `new` is a reserved word and cannot be used in this context. I think his code isn't quite right, looks like a constructor. – Jason Evans Aug 01 '12 at 21:14
  • 3
    `new is a reserved word and cannot be used in this context` thanks. good to know :) – L.B Aug 01 '12 at 21:27
2

The following would compile and seem to fit your scenario minus the fact that you're not using the verbatim identifier @:

public class Base
{
    public Base(myMethod owner)
    {
    }
}

public class @new : Base
{
    public @new(myMethod owner) : base(owner)
    {
    }
}

The previous example demonstrates how to pass a constructor argument down to the base class' implementation.

Alex
  • 34,899
  • 5
  • 77
  • 90