c# - Constructor in Constructor -


is there way how can in c#? can not use this(int,int) in c# code. can write me similar code in c# , same things? thank you! :)

public class javaapplication2 {     public static class someclass      {         private int x;         private int y;          public someclass () { this(90,90); }         public someclass(int x, int y) { this.x = x; this.y = y; }         public void showmevalues ()         {             system.out.print(this.x);             system.out.print(this.y);         }     }     public static void main(string[] args)      {         someclass myclass = new someclass ();         myclass.showmevalues();     } } 

there several things need changed if want translate c#:

  1. the main problem you've declared someclass static. won't compile because static classes cannot have instance members. need remove static keyword.
  2. to invoke constructor need use : this(...) after constructor parameters (or : base(...) invoke constructor of parent class).
  3. instead of system.out, .net applications need use system.console.

this should work you:

public class someclass  {     private int x;     private int y;      public someclass () : this(90,90) { }     public someclass(int x, int y) { this.x = x; this.y = y; }     public void showmevalues ()     {         console.writeline(this.x);         console.writeline(this.y);     } } 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -