C# Possible method to call protected non-static methods in current class? -


I recently picked C # as another language to further my knowledge in other languages, But to use the syntax of the language to experiment, I public static zero main (); This problem was encountered while using the and my calling code in the same class was as follows:

  Nom place testing process {class 1 class} {public static zero main } {System.Console.WriteLine ("This is nothing but a test. \ NInput" test "); Var UserInput = System.Console.ReadLine (); String input = this.ValidateInput (UserInput); System.Console.WriteLine (input); System.Console.WriteLine (); } Protected string ValidateInput (string variable) {var VarReturn = (string) null; If (string. Axles (variable, "test")) {VarReturn = "true \ n"; } And {VarReturn = "wrong \ n"; } VarReturn return; }}}  

Therefore, what I have researched has come to know that you call this syntax Can not use / P>

Then I tried self but it did not take any advantage (like Python, with the permission of PHF language self ), so tried the following :

string input = test process. Class 1 Validity input (user input);

To be presented with the following message:

Error 1 Non-static field, method or property requires object reference 'TestingProject' Class1.ValidateInput (string) 'C: \ Users \ xxx \ AppData \ Local \ Temporary Projects \ ClassProject \ Class1.cs 14 28 ClassProject

Then, I found this little gem Solution of:

  var CurrClass = new square 1 ();  

And this is called a safe method:

  var CurrClass = new Class1 (); String input = CurrClass.ValidateInput (UserInput);  

Who amazed me that this is the only available method of calling non-static private methods, so my overall question is:

What to call Is there any way of non-static methods that are safe / private without introducing a new variable to include existing objects?

The problem is that your main method is static method of a static method object Without an example, even in the same class, non-static approaches can not be reached. This is the complete point of being a static method: You do not have a solid object to work. It is outside the scope of other instance methods.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -