c# - Does passing an object by value create two instances of a file system watcher? -


i have 3 classes. 1 class "worker" class has file system watcher. main form (class a) holds reference each instantiated worker object in list (_workerlist). if pass _workerlist class b (which did via constructor) , save copy of list in class b, mean have 2 instances of file system watcher running @ same time?

public partial class : form {     private list<worker> _workerlist;      public a()     {         initializecomponent();         _workerlist = new list<worker>();     }      private void button_click(object sender, eventargs e)     {         _workerlist.add(new worker());  //the worker class contains file system watcher          using( b b = new b(_workerlist))         {             b.showdialog();         }     } }  public partial class b : form {      private list<worker> _workerlistcopy;      public b(list<worker> originalworkerlist)     {         initializecomponent();         _workerlistcopy = new list<worker>(originalworkerlist)     }  } 

no

but maybe not reasons think. created class called "worker". means automatically reference type. reference types passed value, reference (a copy not made).

you can change object itself, changes reference points @ not reflected original variable.

this means because didn't use new operator again create new worker class, 1 filesystemwatcher created.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -