Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If what you really want is just to retrieve the <code>ID</code> at run-time, without passing any arguments into <code>function1</code>, you can use inherited methods:</p> <pre><code>public abstract class Module { internal int ID; public abstract void ModuleStart(); protected void function1() { System.Console.WriteLine ("function1 called from module {0}", this.ID); } } </code></pre> <p>Then, from your other modules, calling <code>function1</code> looks as simple as this:</p> <pre><code>class MyModule : Module { public override void ModuleStart() { this.function1(); // the 'this.' is not required } } </code></pre> <p>However, I get the sense from your comments that you want to make keep these functions separate from your <code>Module</code> class, since you are routinely adding new functions. You can do almost the exact same thing using <a href="http://msdn.microsoft.com/en-us/library/bb311042.aspx" rel="nofollow">extension methods</a> to maintain the <em>appearance</em> of not passing any parameters:</p> <pre><code>public abstract class Module { internal int ID; public abstract void ModuleStart(); } public static class ModuleExtensions { public static void function1(this Module module) { innerFunction1(module.ID); } internal static void innerFunction1(int ID) { System.Console.WriteLine ("function1 called from module {0}", ID); } } </code></pre> <p>Then, from your other modules, calling <code>function1</code> looks as simple as this:</p> <pre><code>class MyModule : Module { public override void ModuleStart() { this.function1(); // the 'this.' is required } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload