none
[Visual Studio 2015]How do i know how many instances of class were created?

    Question

  • Example i have a class:

    public class CheckInstances{
     int tempVar = 1;
     public CheckInstances(){
     
     }
     public string TestReturnString(){
      return "Hello world";
     }
    }

    ..and each times i used method:

    new CheckInstances();
    How to known instances of class were created by Visual Studio IDE GUI?


    Monday, May 16, 2016 4:39 AM

Answers

  • Hi,

    by default there is nobody eho counts the number of instances of your class. And Visual Studio IDE GUI is not creating any instances (except when it is a control. In such a case the designer will create instances when required).

    The IDE (or debugger) can start the application and attach the debugger but it is not doing anything else.

    If you want something like that then you have to implement that on your own. So you could add a static variable that you use for counting. Inside the constructor, you increase the value. And you can add a method that returns that value.

    With kind regards,

    Konrad

    Monday, May 16, 2016 4:47 AM
    Moderator

All replies

  • Hi,

    by default there is nobody eho counts the number of instances of your class. And Visual Studio IDE GUI is not creating any instances (except when it is a control. In such a case the designer will create instances when required).

    The IDE (or debugger) can start the application and attach the debugger but it is not doing anything else.

    If you want something like that then you have to implement that on your own. So you could add a static variable that you use for counting. Inside the constructor, you increase the value. And you can add a method that returns that value.

    With kind regards,

    Konrad

    Monday, May 16, 2016 4:47 AM
    Moderator
  • Thanks konrad!
    Monday, May 16, 2016 5:46 AM