It is impossible to figure out how to pass a parameter to it when calling a method, except to indicate it explicitly in the first method. The idea of ​​the task is to create in the separate Two class the one () method, which should call the already existing method of the One class so as not to duplicate the code.

class One { public static double one(Two two) { // Всё, что пришло в голову это - задать явно значения: // two.X = 1; two.Y = 1; return two.X + two.Y; } } class Two { public int X; public int Y; public double one() { return One.one(this); } } class Program { public static void Main() { Console.WriteLine(new Two().two()); } } 
  • (new Two(){ X = 1, Y = 2 }).one() - Igor
  • Your code looks meaningless. What problem do you solve? What do you want to make these code? Where was the duplication originally? What did the initial code look like? - tym32167
  • Well, after you have created an instance, set its fields to values: new Two() { X = 1, Y =1 }; - Andrey NOP
  • You have default values ​​for the fields in the object, either use the object initializer as specified above or accept the x and y values ​​as parameters in the constructor. Btw public fields are bad, use at least properties. - yolosora
  • one
    And the idea of ​​transferring yourself to a method of another class purely to conduct operations on your own fields looks somehow strange in this case ... - yolosora

0