Answer the question
In order to leave comments, you need to log in
Referring to one class from two others C# .Net?
Hi, maybe I'm a noob (well, it's understandable, I recently started learning the language), but now I got into an unpleasant situation, when accessing one class from the other two, an error occurs: Process is terminated due to StackOverflowException. , such
Who could help, here is the code example of how I do it:
public class MainClass{
Parametrs par = new Parametrs();
par.hps();
}
public class Dog{
Parametrs p = new Parametrs();
p.start()
}
public class Parametrs{
public int hp;
public void hps(){
hp = hp - 1;
}
public void start(){
Console.WriteLine("Запуск пошёл");
}
}
Answer the question
In order to leave comments, you need to log in
Read https://metanit.com/sharp/ and how to format the code (there is no style example in the online editor).
Your example is https://dotnetfiddle.net/cxLent
And yes, as already reported in the comments, there is no error here.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question