Note that there are some explanatory texts on larger screens.

plurals
  1. POC Sharp - Interfaces which Require Object References
    primarykey
    data
    text
    <p>For some reason when I call a namespace within this class, I get an error which states that it requires an object reference. I thought that using a reference variable of the IMethodResponses type would allow me to access a method within its own creation, but I can't accomplish this, and nor can I simply just implement the interface without a reference and use its methods...</p> <p>Can someone help me out with this? I'll post the Interface itself too in case their's something wrong. I should probably note that I haven't been doing this very long. </p> <p>//Class Implementing Interface:</p> <pre><code>internal sealed class Name : INameCreation, IMethodResponses { public ScratchCreate create = ScratchCreate.create; ListCreate select = new ListCreate(); public IMethodResponses _responses = IMethodResponses; //&lt;--Error public static void ChooseName() { int response; Console.WriteLine("Press \'1\' to select from a list of names, or \'2\' to create your own."); Console.WriteLine("If you wish to quit, you may do so by pressing \'0\'"); response = int.Parse(Console.ReadLine()); do { Console.WriteLine("Sorry, you didn't enter any of the correct responses..."); Console.WriteLine("Press \'1\' to select from a list of names, or \'2\' to create your own."); Console.WriteLine("If you wish to quit, you may do so by pressing \'0\'"); response = int.Parse(Console.ReadLine()); } while (response != 0 || response != 1 || response != 2); _responses.IntegerResponse(response); } public void IntegerResponse(int response) { switch (response) { case 0: Console.WriteLine("Goodbye!"); break; case 1: break; case 2: break; } } </code></pre> <p>//Interface:</p> <pre><code>namespace PlayerCreation { public interface INameCreation { } public interface IMethodResponses { void IntegerResponse(int response); void StringResponse(string response); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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