c# - ref modifier for ...reference types
<p>I am a bit confused about this piece of code.</p>

<pre><code>    public static void Foo(A p)
    {
        p.SomeProp = "ccc";
        p = null; // !!!
    }

    static void Main(string[] args)
    {
        A p = new A();
        Foo(p);

        Console.WriteLine("SomeProp is: " + p.SomeProp);
        Console.ReadLine();
    }
</code></pre>

<p>The output is: </p>

<p><strong>"SomeProp is: ccc</strong>" </p>

<p>But I would have expected a NullReferenceException.</p>

<p><br /></p>

<p>However, if I change it like so, using the ref modifier:</p>

<pre><code>    public static void Foo(ref A p)
    {
        p.SomeProp = "ccc";
        p = null;
    }

    static void Main(string[] args)
    {
        A p = new A();
        Foo(ref p);

        Console.WriteLine("SomeProp is: " + p.SomeProp);
        Console.ReadLine();
    }
</code></pre>

<p>I get a NullReferenceException - the second one is understandable for me.</p>

<p>But how can it be, that in the first piece of code p is NOT set to null, but the property gets its value set? </p>

<p>My question is: what is the p argument of the Foo method in the first piece of code if it is not a reference to the orginal instance?</p>

<p><hr /></p>

<p>Btw. here is the definition of class A</p>

<pre><code>public class A
{
    public string SomeProp;
}
</code></pre>
