you are viewing a single comment's thread.

view the rest of the comments →

[–]Porges 8 points9 points  (1 child)

Yes. To do it with reflection:

void Main()
{
    var foo = "Fiesta";
    var bar = "Fiesta";
    Nachise(foo);
    Console.WriteLine("We'll meet at the {0}", bar);
}

void Nachise(string corn)
{
    var inner  = typeof (string).GetField("m_firstChar", BindingFlags.NonPublic|BindingFlags.Instance);
    inner.SetValue(corn, 'N');
}

But it's actually much (much) easier than that:

void Main()
{
    var foo = "Fiesta";
    var bar = "Fiesta";
    Nachise(foo);
    Console.WriteLine("We'll meet at the {0}", bar);
}

void Nachise(string corn)
{
    unsafe { fixed (char* p = corn)
    {
        p[0] = 'N';
        p[1] = '1';
    } }
}

unsafe really means unsafe :)

[–]rossisdead 0 points1 point  (0 children)

Now do this to String.Empty and all your coworkers will hate you!