Assigning code to a variable

You could assign it to an Action like this:

var ButtonClicked = new Action(() => MessageBox.Show("hi"));

Then call it:

ButtonClicked();

For completeness (in regards to the various comments)...

As Erik stated, you could execute multiple lines of code:

var ButtonClicked = new Action(() =>
{
    MessageBox.Show("hi");

    MessageBox.Show("something else");  // something more useful than another popup ;)
});

As Tim stated, you could omit the Action keyword

Action ButtonClicked = () => MessageBox.Show("hi");

Action ButtonClicked = () =>
{
    // multiple lines of code
};

To address KRyan's comment, regarding the empty parentheses, that represents the list of parameters you want to be able to send to the Action (in this case, none).

If, for instance, you wanted to specify the message to show, you could add "message" as a parameter (note that I changed Action to Action<string> in order to specify a single string parameter):

Action<string> ButtonClicked = (message) => MessageBox.Show(message);

ButtonClicked("hello world!");

In your case, you want to use a delegate.

Let's see how a delegate works and how we can get to an easier form by understanding its concept:

// Create a normal function
void OnButtonClick()
{
    MessageBox.Show("Hello World!");
}
// Now we create a delegate called ButtonClick
delegate void ButtonClick();

You see, the delegate takes the form of a normal function but without any arguments (It could take any amount of arguments just like any other method, but for the sake of simplicity, it doesn't).

Now, let's use what we have; we will define the delegate just as we define any other variable:

ButtonClick ButtonClicked = new ButtonClick(OnButtonClick);

We basically created a new variable called ButtonClicked, that has a type of ButtonClick (which is a delegate) and that when used, will execute the method in the OnButtonClick() method.
To use it we simply call: ButtonClicked();

So the whole code would be:

delegate void ButtonClick();

void OnButtonClick()
{
    MessageBox.Show("Hello World!");
}

void Foo()
{
    ButtonClick ButtonClicked = new ButtonClick(OnButtonClick);
    ButtonClicked(); // Execute the function.
}  

From here, we can move to lambda expressions and see how they could be useful in your situation:
There are many delegates already defined by .NET libraries, with some like Action, which do not accept any parameter and does no return a value. It is defined as public delegate void Action();
You can always use it to your needs instead of the need of defining a new delegate every time. In the previous context for example, you could had just written

Action ButtonClicked = new Action(OnButtonClick);
ButtonClicked();

which would had done the same.
Now that you saw different ways of how to use delegates, let's use our first lambda expression. Lambda expressions are anonymous functions; so, they are normal functions but without a name. They are of those forms:

x => DoSomethingWithX(x);
(x) => DoSomethingWithX(x);
(x,y) => DoSometingWithXY(x,y);
() => Console.WriteLine("I do not have parameters!");

In our case, we do not have any parameters so we will use the last expression. We can use this just as the OnButtonClick function, but we get the advantage of not having a named function. We can instead do something like this:

Action ButtonClicked = new Action( () => MessageBox.Show("Hello World!") );

or even easier,

Action ButtonClicked = () => MessageBox.Show("Hello World!");

then simply call ButtonClicked(); Of course you can also have multi-lines of code, but I do not want to confuse you more. It would look like this though:

Action ButtonClicked = () => 
{
    MessageBox.Show("Hello World!");
};
ButtonClicked();

You could also play around, for example, you can execute a function like this:

new Action(() => MessageBox.Show("Hello World!"))();

Sorry for the long post, hope it was not too confusing :)

EDIT: I forgot to mention that an alternate form which, even though not often used, could make lambda expressions easier to understand:

new Action(delegate() {
    Console.WriteLine("I am parameterless");
})();

Also, using generics:

// Defines a delegate that has one parameter of type string. You could pass as many parameters as you want.
new Action<string>(delegate(string x) {
    Console.WriteLine(x);
})("I am a string parameter!");

In turn you could use lambda expressions, but you do not need (but might in some cases) to define the type of the parameter, for example, the code above could simply be written as:

new Action<string>(x => {
    Console.WriteLine(x);
})("I am a string parameter!");

or:

new Action<string>(x => Console.WriteLine(x))("I am a string parameter!");

EDIT2:
Action<string> is a representation of public void delegate Action(string obj);
Action<string,string> is a representation of public void delegate Action(string obj, string obj2);
In general, Action<T> is a representation of public void delegate Action<T>(T obj);

EDIT3: I know the post has been here for a while, but I think this is really cool to not mention: You can do this, which is mostly related to your question:

dynamic aFunction = (Func<string, DialogResult>)MessageBox.Show;
aFunction("Hello, world!");

or simply:

Func<string, DialogResult> aFunction = MessageBox.Show;
aFunction("Hello, world!");

The Lazy class is specifically designed to represent a value that won't be computed until you ask for it. You construct it by providing a method that defines how it should be constructed, but it will handle executing that method no more than once (even in the face of multiple threads requesting the value) and simply returning the already constructed value for any additional requests:

var foo = new Lazy<DialogResult>(()=>MessageBox.Show("Hello, World!"));

var result = foo.Value;

The way I'm reading your question, this is in the context of GUI controls?

If this is in WPF, take a look at the "right" way to handle commands from controls: http://msdn.microsoft.com/en-us/library/ms752308(v=vs.110).aspx

...but that can be a pain and overkill. For a simpler general case, you might be looking for an event handler, like:

myButton.Click += (o, e) => MessageBox.Show("Hello, World!");

That event handler can be handled a variety of ways. The above example uses an anonymous function, but you could also do:

Action<object, RoutedEventArgs> sayHello = (o, e) => MessageBox.Show("Hello, World");
myButton.Click += new RoutedEventHandler(sayHello);

...just like you were asking, with a function (or here, "Action", since it returns void) assigned as a variable.