limit method to only be called by a particular class
<p>I want a particular method in one class to only be accessible by a particular class.  For example:</p>

<pre><code>public class A
{
  public void LimitedAccess() {}
  public void FullAccess() {}
}

public class B
{
  public void Func()
  {
     A a = new A();
     a.LimitedAccess();       // want to be able to call this only from class B
  }
} 

public class C
{
  public void Func()
  {
     A a = new A();
     a.FullAccess();           // want to be able to call this method
     a.LimitedAccess();        // but want this to fail compile
  }
} 
</code></pre>

<p>Is there is a keyword or attribute that I can use to enforce this?</p>

<p><strong>UPDATE:</strong></p>

<p>Due to existing system complexity and time constraints, I needed a low impact solution.  And I wanted something to indicate at compile time that LimitedAccess() could not be used.  I trust Jon Skeet's answer that exactly what I had asked for could not be done in C#.  </p>

<p>The question and Jon's answer are good for those who may run across this later.  And the fact that this design smells can hopefully veer anyone away for choosing something like this as a desired a solution.</p>

<p>As mentioned in a comment, the <a href="http://stackoverflow.com/questions/203616/why-does-c-sharp-not-provide-the-c-style-friend-keyword">C# friend</a> conversation is useful reading if you are trying to solve a similar situation.</p>

<p>As for my particular solution:  "why would A contain B's logic" (asked by @sysexpand in comments). That's the rub.  <code>B.Func()</code> was called throughout the system I'm working on, but it primarily operated on a singleton of <code>A</code>. So what I ended up doing was moving <code>B</code>'s <code>Func()</code> into <code>A</code> and making <code>A.LimitedAccess()</code> private. There were a few other details to work around, as there always are, but I got a low impact solution that gave me compile-time errors on callers to <code>A.LimitedAccess()</code>. </p>

<p>Thanks for the discussion.</p>
