title: How to communicate between two classes in c#?
body: <p>I have two classes <code>A</code> and <code>B</code>. Class <code>A</code> has an instance of class <code>B</code>. Class <code>A</code> has a list of Class <code>Foo</code> with attributes <code>Id</code> and <code>Name</code> which is dynamic. As the <code>Run</code> method of class <code>B</code> is called, the local variable <code>id</code> in class <code>B</code> is calculated. Suppose the value of <code>id</code> is 2, I need to search <code>dynamicList</code> and get "Two" back.</p>
  
  <blockquote>
    <p>The <code>dynamicList</code> can be updated by an event.</p>
  </blockquote>
  
  <pre><code>class Foo()
  {
      public Foo(int id, string name)
      {
          this.Id = id;
          this.Name = name;
      }
      public int Id { get; set; }
      public string Name { get; set; }
  }
  
  class A
  {
      public A()
      {
          this.dynamicList.Add(new Foo(1, "One"));
          this.dynamicList.Add(new Foo(2, "Two"));
          this.dynamicList.Add(new Foo(3, "Three"));
  
          b = B();
          b.Run();
      }
      public List&lt;Foo&gt; dynamicList = new List&lt;Foo&gt;();
  }
  
  class B 
  {
      public void Run()
      {
          while(true)
          {
              int id;
              string name;
  
              // an event appended this.dynamicList.Add(new Foo(4, "Four"));
              // an event appended this.dynamicList.Add(new Foo(5, "Five"));
  
  
              // some code goes here that gets the value of id 4
              id = 4;
  
              // I need to convert the value of '4' to 'Four'
          }
      }
  }
  </code></pre>
  
  <blockquote>
    <p>I have two classes <code>A</code> and <code>B</code>. Class <code>A</code> has an instance of class
    <code>B</code>. Class <code>A</code> has a list of Class <code>Foo</code> with attributes <code>Id</code> and
    <code>Name</code> which is dynamic. As the <code>Run</code> method of class <code>B</code> is called,
    the local variable <code>id</code> in class <code>B</code> is calculated. Suppose the value
    of <code>id</code> is 2, I need to search <code>dynamicList</code> and get "Two" back.</p>
  
  <pre><code>class Foo()
  {
    public Foo(int id, string name)
    {
        this.Id = id;
        this.Name = name;
    }
    public int Id { get; set; }
    public string Name { get; set; }
  }
  
  class A
  {
    public A()
    {
        this.dynamicList.Add(new Foo(1, "One"));
        this.dynamicList.Add(new Foo(2, "Two"));
        this.dynamicList.Add(new Foo(3, "Three"));
  
        b = B();
        b.Run();
    }
      public List&lt;Foo&gt; dynamicList = new List&lt;Foo&gt;();
  }
  
  class B 
  {
    public void Run()
    {
        while(true)
        {
            int id;
              string name;
  
            // some code goes here that gets the value of id 2
            id = 2;
  
            // I need to convert the value of '2' to 'Two'
  
        }
    }
  }
  </code></pre>
  </blockquote>